用macros导入分隔文件到Excel(.CommandType = 0)

很多类似的问题正在进行,但谷歌和堆栈溢出没有触及我认为我需要的部分。 我正在试图用macros导入一个pipe道分隔的文本文件。 当我录制macros,这是我得到:

With ActiveSheet.QueryTables.Add(Connection:= _ "TEXT;C:\Users\johnsmith\Desktop\Macro Tinkering\ABC_Financials_ALL(Delimited).txt" _ , Destination:=Range("$A$1")) .CommandType = 0 .Name = "ABC_Financials_ALL(Delimited)_1" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .TextFilePromptOnRefresh = False .TextFilePlatform = 437 .TextFileStartRow = 1 .TextFileParseType = xlDelimited .TextFileTextQualifier = xlTextQualifierDoubleQuote .TextFileConsecutiveDelimiter = False .TextFileTabDelimiter = False .TextFileSemicolonDelimiter = False .TextFileCommaDelimiter = False .TextFileSpaceDelimiter = False .TextFileOtherDelimiter = "|" .TextFileColumnDataTypes = Array(2, 2, 2, 2, 2) .TextFileTrailingMinusNumbers = True .Refresh BackgroundQuery:=False End With 

当我尝试运行macros,它失败了,当我debugging时,它指向我的方向“.CommandType = 0”

任何人都知道是否有一个价值,会让这个macros? 还是我的问题比这更糟?

好的。

更有信心在删除可能的垃圾Mukul215的build议,我不断删除的东西,并重试。

 With ActiveSheet.QueryTables.Add(Connection:= _ "TEXT;C:\Users\johnsmith\Desktop\Macro Tinkering\ABC_Financials_ALL(Delimited).txt" _ , Destination:=Range("$A$1")) .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .TextFilePromptOnRefresh = False .TextFilePlatform = 437 .TextFileStartRow = 1 .TextFileParseType = xlDelimited .TextFileTextQualifier = xlTextQualifierDoubleQuote .TextFileConsecutiveDelimiter = False .TextFileTabDelimiter = False .TextFileSemicolonDelimiter = False .TextFileCommaDelimiter = False .TextFileSpaceDelimiter = False .TextFileOtherDelimiter = "|" .TextFileColumnDataTypes = Array(2, 2, 2, 2, 2) .TextFileTrailingMinusNumbers = True .Refresh BackgroundQuery:=False End With 

而这一个呢。