excel 2010刷新背景查询中的运行时错误1004
我试图用vba编写一个脚本,将几个文本文件导入excel(一张工作表),然后在一个图形上绘制它们。 我在Refresh BackgroundQuery commant中遇到问题,遇到1004运行时错误 我怎么才能算出来 谢谢, 埃亚尔 这是我的密码:excel 2010刷新背景查询中的运行时错误1004,excel,vba,macos,Excel,Vba,Macos,我试图用vba编写一个脚本,将几个文本文件导入excel(一张工作表),然后在一个图形上绘制它们。 我在Refresh BackgroundQuery commant中遇到问题,遇到1004运行时错误 我怎么才能算出来 谢谢, 埃亚尔 这是我的密码: Sub fring1() Dim fpath As String Dim fname As String Dim i As Integer fpath = "C:\Users\epinkas\Desktop\Yo
Sub fring1()
Dim fpath As String
Dim fname As String
Dim i As Integer
fpath = "C:\Users\epinkas\Desktop\Yossi\"
fname = fpath & "*.txt"
Name = Dir(fname)
While Name <> ""
With Sheet1.QueryTables.Add(Connection:= _
"TEXT;fpath & Name", _
Destination:=Range("$A$1"))
.Name = fpath & Name
.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 = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
ActiveChart.SetSourceData Source:=Range("Sheet1!$A$1:$A$1356")
Name = Dir()
Wend
End Sub
Sub-fring1()
作为字符串的Dim fpath
作为字符串的Dim fname
作为整数的Dim i
fpath=“C:\Users\epikas\Desktop\Yossi\”
fname=fpath&“*.txt”
Name=Dir(fname)
而名称为“”
带Sheet1.QueryTables.Add(连接:=_
“文本;路径和名称”_
目的地:=范围(“$A$1”))
.Name=fpath和Name
.FieldNames=True
.rowNumber=False
.FillAdjacentFormulas=False
.PreserveFormatting=True
.refreshinfoleopen=False
.RefreshStyle=xlInsertDeleteCells
.SavePassword=False
.SaveData=True
.AdjustColumnWidth=True
.RefreshPeriod=0
.TextFilePromptOnRefresh=False
.TextFilePlatform=437
.TextFileStartRow=1
.TextFileParseType=xlDelimited
.TextFileTextQualifier=xlTextQualifierDoubleQuote
.textfileconsutivedelimiter=False
.TextFileTabDelimiter=True
.TextFileSemicolonDelimiter=False
.textfilecommadelimitor=False
.TextFileSpaceDelimiter=False
.TextFileColumnDataTypes=数组(1)
.TextFileTrailingMinusNumbers=True
.Refresh BackgroundQuery:=False
以
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType=xlxySpatterSmoothNoMarkers
ActiveChart.SetSourceData源:=范围(“Sheet1!$A$1:$A$1356”)
Name=Dir()
温德
端接头
看起来您正试图在带引号的字符串中使用路径和文件名变量。将变量连接到带引号的字符串中
With Sheet1.QueryTables.Add(Connection:= _
"TEXT;" & fpath & Name, _
Destination:=Range("$A$1"))
这应该将变量的值放入字符串中,而不是它们的变量名。太好了!谢谢您知道如何在同一图表上显示所有导入的数据吗?