以下VBA代码是从CSV文件中提取数据的宏的一部分 . 它在运行Excel 2007和2010的许多PC上运行良好,但在运行Excel 2013的PC上出现以下错误失败 .
'运行时错误1004:应用程序定义的错误或对象定义的错误'
错误发生在以下行
.Refresh BackgroundQuery:=False
如果我注释掉这一行,我不会收到错误,但我也没有导入数据 .
任何帮助都将被感激地接受 .
With ActiveSheet.QueryTables.Add(Connection:=connectionName, Destination:=Range("$A$1"))
.Name = "por800.csv"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With