如何将多个.TXT文本文件合并到一个excel表中
将要合并的多个.TXT文本置于同一个文件夹中,并新建excel表格。在excel中输入以下代码:
Sub all_contents()
Application.ScreenUpdating = False
P = ActiveWorkbook.Path & "/"
N = 1
For Each File In CreateObject("Scripting.FilesyStemObject").GetFolder(P).Files
If File.Name Like "*.TXT" Then
S = CreateObject("Scripting.FileSystemObject").OpenTextFile(P & File.Name, 1, False).ReadAll()
T = Split(S, vbLf)
Cells(N, 1).Resize(UBound(T) + 1, 1) = Application.Transpose(T)
End If
N = N + UBound(T)
Next
Application.ScreenUpdating = True
MsgBox "恭喜大人,已成功合并文本。"
End Sub