|
请问:现在我有近千个TXT文本数据,0001.txt~0999.txt,每一个都需要单独导入新的Excel工作表,数据——导入外部数据——导入数据,然后设置一些,完成之后,另存为0001.xls~0999.xls。
每一个的过程虽然很简单都一模一样,但是我现在有近千个,那还不累死人啦?!请问有什么批处理的方法吗?用宏可以吗?如果可以的话请看下面我录制的语句,需要修改什么地方?!据说把路径文件名改成变量就行了?怎样修改,谢谢!
Sub Macro1()
'
' Macro1 Macro
' 宏由 User 录制,时间: 2008-8-21
'
'
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;D:\xxx\0001.txt" _
, Destination:=Range("A1"))
.Name = "AIDC-0121"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 936
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = "|"
.TextFileColumnDataTypes = Array(2, 1, 2, 1, 1, 1, 1, 1, 1, 2, 9)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
ActiveWorkbook.SaveAs Filename:= _
"D:\xxx\0001.xls", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False
End Sub |
|