Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vbscript 运行时错误1004,应用程序定义或对象定义错误_Vbscript - Fatal编程技术网

Vbscript 运行时错误1004,应用程序定义或对象定义错误

Vbscript 运行时错误1004,应用程序定义或对象定义错误,vbscript,Vbscript,我已经编写了vbscript代码来添加excel第1页中的图表,其源代码来自同一excel的另一张表,其名称为“CL.1.1”,但我收到了上述错误,任何人都可以帮助我解决以下代码中的错误 Sub DispvsTime(Shname) Sheets("Sheet1").Select noofsheets = ActiveSheet.ChartObjects.Count If noofsheets > 0 Then ActiveSheet.ChartObj

我已经编写了vbscript代码来添加excel第1页中的图表,其源代码来自同一excel的另一张表,其名称为“CL.1.1”,但我收到了上述错误,任何人都可以帮助我解决以下代码中的错误

Sub DispvsTime(Shname)
    Sheets("Sheet1").Select
    noofsheets = ActiveSheet.ChartObjects.Count
    If noofsheets > 0 Then
       ActiveSheet.ChartObjects.Select
       ActiveSheet.ChartObjects.Delete
    End If
    Sheets("Sheet1").Pictures.Visible = False
    ActiveSheet.Shapes.AddChart(1000, 420, 50, 500).Select
    ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
    ActiveChart.SetSourceData Source:=Sheets("Shname").Range("G2:H2001")
    ActiveChart.SetElement (msoElementChartTitleAboveChart)
    ActiveChart.ChartTitle.Text = "Displacement VS Time"
End Sub
这里的“shname”是拾取数据的工作表的名称。

行不应该

ActiveChart.SetSourceData Source:=Sheets("Shname").Range("G2:H2001")

因为您希望使用变量Shname,而不仅仅是名为“Shname”的工作表


希望这有帮助

实际上,我只在调试代码时才使用shname,因为它为工作表提供了正确的名称。shname变量被实际值替换,但我仍然面临这个问题
ActiveChart.SetSourceData Source:=Sheets(Shname).Range("G2:H2001")