2007已经取消了filesearch
Sub getdata()
directory = "g:\try\source"
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
Columns("A:A").Select
Application.CutCopyMode = False
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=True, Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 1)), TrailingMinusNumbers:=True
Selection.ColumnWidth = 18
Columns("B:B").ColumnWidth = 18
End With
Next i
Else
MsgBox "There were no files found."
End If
End With
你的赞赏是我坚持原创的动力
赞赏
共 0 人赞赏