[Visual Basic] 纯文本查看 复制代码 Private Sub CommandButton3_Click()
Dim TextFilePath As String
Dim TextFile As Integer
Dim FileContent As String
Dim FileLines() As String
Dim SplitLine() As String
Dim i As Long
'获取要导入的文件路径
TextFilePath = Cells(1, 2)
'打开文件
TextFile = FreeFile
Open TextFilePath For Input As TextFile
'读取文件内容
FileContent = Input(LOF(TextFile), TextFile)
'关闭文件
Close TextFile
'以%为分隔符拆分文件内容
FileContent = Replace(Replace(FileContent, Chr(10), ""), Chr(13), "")
FileLines = Split(FileContent, Cells(3, 2))
'逐行写入并保存文件
For i = 1 To UBound(FileLines)
'以%后面5个字符为文件名
Open Cells(2, 2) & Left(FileLines(i), 5) & ".txt" For Output As #1
Print #1, FileLines(i)
Close #1
Next i
'提示导入完成
MsgBox "导入完成!"
End Sub
|