|
Sub test()
Dim p$, f$, A, i&, r&
Application.ScreenUpdating = False
Cells.Clear
p = ThisWorkbook.Path & "\"
f = Dir(p & "*.txt")
Do While f <> ""
i = i + 1
'读取文本
Open p & f For Input As #1
A = Split(StrConv(InputB(LOF(1), 1), vbUnicode), vbCrLf)
Close #1
'导入到工作表
r = Range("b65536").End(xlUp).Row + 1
Cells(r, 2).Resize(UBound(A), 1) = Application.Transpose(A)
If i <> 1 Then Cells(r, 1) = 1
f = Dir
Loop
'整理
Range("a:a").SpecialCells(xlCellTypeConstants).EntireRow.Delete
Rows(1).Delete
Columns(1).Delete
Columns("A:A").TextToColumns Comma:=True
' Range("a1").CurrentRegion.EntireColumn.AutoFit
End Sub
多个txt文件合并成excel文件2.rar
(17.25 KB, 下载次数: 9)
|
|