把txt文件全部放入一个文件夹里,然后把txt文档文件批量导入一个excel文件中,第一列为文件名,第二列为对应文本文件里面第一列的数据,第三列为对应文本文件里面第二列的数据。
Sub tqwb()
Dim a$, b$, i%
Dim txtName
txtName = Dir(ThisWorkbook.Path & "\*.txt")
Range("a:c").ClearContents
[a1:c1] = [{"文件名称","编号","数量"}]
n = 2
Do While txtName <> ""
Open ThisWorkbook.Path & "\" & txtName For Input As #1
Do While Not EOF(1)
Input #1, a, b
Cells(n, 1) = Replace(txtName, ".txt", "")
Cells(n, 2) = a
Cells(n, 3) = b
n = n + 1
Loop
Close #1
txtName = Dir
Loop
End Sub
根据自己需求改