【发布时间】:2016-09-26 02:45:36
【问题描述】:
我不确定这是否是问题的正确位置,但这有点超出我的知识库。
我的问题是我有一段代码只是导入文本文档并使用空格分隔符。我在我的终端上多次使用过这段代码,它可以工作。但是,当我在某个不同的终端上运行它时,我得到了一个错误,其他时候它很好。
我的代码是:
暗淡
Ret = Application.GetOpenFilename("Text Files (*.txt), *.txt")
If Ret <> False Then
With Sheets("Primary").QueryTables.Add(Connection:= _
"TEXT;" & Ret, Destination:=Workbooks("Importer").Sheets("Primary").Range("$A$1"))
.Name = "Sample"
.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 = True
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = True
.TextFileColumnDataTypes = Array(xlTextFormat, xlTextFormat, xlTextFormat, xlTextFormat, xlTextFormat, xlTextFormat, xlTextFormat, xlTextFormat, xlTextFormat, xlTextFormat, xlTextFormat, xlTextFormat, xlTextFormat, xlTextFormat, xlTextFormat, xlTextFormat, xlTextFormat, xlTextFormat, xlTextFormat, xlTextFormat)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End If
我在运行此代码时收到“运行时错误 9:下标超出范围”。调试菜单为问题选择此代码:
With Sheets("Primary").QueryTables.Add(Connection:= _ “文本;” & Ret, Destination:=Workbooks("Importer").Sheets("Primary").Range("$A$1"))
我不明白仅在某些计算机终端上导致此问题的原因。据我所知,我们所有的 Excel 程序都设置相同。
任何帮助将不胜感激。
【问题讨论】: