张雄友 发表于 2015-1-4 19:33
不行的。
Sub 导入()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = ThisWorkbook.Path & "\"
If .Show = False Then Exit Sub
FilePath = .SelectedItems(1) & "\"
End With
FileName = Dir(FilePath & "*.txt")
For Each sh In Sheets
If sh.Name <> "get" Then sh.Delete
Next
Do Until Len(FileName) = 0
Sheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = Left(FileName, Len(FileName) - 4)
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & FilePath & FileName, Destination:=Range( _
"$A$1"))
.TextFileOtherDelimiter = "/"
.TextFileTrailingMinusNumbers = True
.TextFileColumnDataTypes = Array(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, _
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)
.Refresh BackgroundQuery:=False
S = [a1]
If InStr(S, "?") <> 0 Then
[a1] = Split(S, "?")(1)
End If
End With
FileName = Dir
Loop
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub