试试这个
------------------
Sub micro123()
directory = "C:\txtTemp" '你存放txt文件的目录
With Application.FileSearch
.LookIn = directory
.SearchSubFolders = True
.Filename = "*.txt"
If .Execute() > 0 Then
MsgBox "There were " & .FoundFiles.Count & " file(s) found."
For i = 1 To .FoundFiles.Count
Sheets.Add
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & .FoundFiles(i), Destination:=ActiveSheet.Range("A1"))
.Refresh BackgroundQuery:=False
End With
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub
-----------
你把--------------中间的代码复制,打开excel,按下alt+f11,菜单栏-插入-模块,在编辑区域粘贴代码,然后运行。(运行时如出现安全提示,可放心通过,让宏运行)
注意的是,这些代码是在2003下运行的,2007去除了FileSearch de 的支持。可以使用Dir 或 FileSystemObject来搜索...详见:
http://support.microsoft.com/kb/920229/zh-cn