|
倒是可以实现,不过代码简单了点,并且执行效率不高,如果导入文件数量不是太多应该没问题,如果文件太多可能等待时间比较长。
Sub getdata_from_dats()
Application.ScreenUpdating = False
Set myDialog = Application.FileDialog(msoFileDialogFilePicker)
With myDialog
.Filters.Clear
.Filters.Add "所有 dat 文件", "*.dat", 1
.AllowMultiSelect = True
If .Show = -1 Then
For Each oSel In .SelectedItems
xname1 = Mid(oSel, InStrRev(oSel, "\") + 1, Len(oSel) - InStrRev(oSel, "\") - 4)
Workbooks.OpenText filename:=oSel, Origin:=936, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=True, Tab:=True, Semicolon:=False, Comma:=False, _
Space:=True, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3 _
, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1)), TrailingMinusNumbers:=True
ActiveSheet.UsedRange.Copy
GetObject(oSel).Close False
ThisWorkbook.Activate
If Cells(1, 1) = "" Then Mrow = 1 Else Mrow = ActiveSheet.UsedRange.Rows.Count + 1
Cells(Mrow, 1).Value = xname1
Cells(Mrow, 2).Select
ActiveSheet.Paste
Next
End If
End With
Application.ScreenUpdating = False
End Sub
|
|