'主程序
Sub test()
Application.ScreenUpdating = False
Call test1
Call test2
End Sub
'清除工作表
Sub test1()
Dim x
Application.DisplayAlerts = False
For Each x In Sheets
If x.Name <> "Sheet1" Then x.Delete
Next x
End Sub
'查找文本
Sub test2()
Dim p, f
p = ThisWorkbook.Path & "\"
f = Dir(p & "*.txt")
Do While f <> ""
Call test3(p, f)
f = Dir
Loop
End Sub
'文本导入工作表
Sub test3(p, f)
Dim A
Open p & f For Input As #1
A = Split(StrConv(InputB(LOF(1), 1), vbUnicode), vbCrLf)
Close #1
Sheets.Add after:=Sheets(Sheets.Count)
Range("a1").Resize(UBound(A) + 1) = Application.Transpose(A)
Range("a:a").TextToColumns ConsecutiveDelimiter:=True, Space:=True '按空格分列
ActiveSheet.Name = f
End Sub
导入.rar
(12.13 KB, 下载次数: 21)