0

我已经编写了 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”是选取数据的工作表的名称。

4

1 回答 1

0

不应该线

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

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

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

希望这可以帮助!

于 2013-05-10T09:32:54.537 回答