VBA错误"未找到方法或数据Memeber ..."使用.chartdata时

时间:2015-07-08 13:02:51

标签: vba charts powerpoint

希望有人可以提供帮助。我是新手,大局是我试图用excel表格中的数据改变ppt幻灯片上现有图表上的数据。 简单的问题是,当我尝试创建新图表时,我收到错误:

方法或数据未在线找到成员 Set gChartData = myChart.ChartData

为什么.ChartData不是mChart后面的VBA菜单中的选项? 我正在运行Office Pro Plus 2010.我已检查MS Powerpoint 14.0对象库参考。 感谢

Sub CreateChart()
Dim myChart As Chart
Dim gChartData As ChartData
Dim gWorkBook As Excel.Workbook
Dim gWorkSheet As Excel.Worksheet

' Create the chart and set a reference to the chart data.
Set myChart = ActivePresentation.Slides(1).Shapes.AddChart.Chart
Set gChartData = myChart.ChartData

' Set the Workbook and Worksheet references.
Set gWorkBook = gChartData.Workbook
Set gWorkSheet = gWorkBook.Worksheets(1)

 ' Add the data to the workbook.
gWorkSheet.ListObjects("Table1").Resize gWorkSheet.Range("A1:B5")
gWorkSheet.Range("Table1[[#Headers],[Series 1]]").Value = "Items"
gWorkSheet.Range("a2").Value = "Coffee"
gWorkSheet.Range("a3").Value = "Soda"
gWorkSheet.Range("a4").Value = "Tea"
gWorkSheet.Range("a5").Value = "Water"
gWorkSheet.Range("b2").Value = "1000"
gWorkSheet.Range("b3").Value = "2500"
gWorkSheet.Range("b4").Value = "4000"
gWorkSheet.Range("b5").Value = "3000"

' Apply styles to the chart.
With myChart
    .ChartStyle = 4
    .ApplyLayout 4
    .ClearToMatchStyle
End With

' Add the axis title.
With myChart.Axes(xlValue)
    .HasTitle = True
    .AxisTitle.Text = "Units"
End With

'myChart.ApplyDataLabels

' Clean up the references.
Set gWorkSheet = Nothing
' gWorkBook.Application.Quit
Set gWorkBook = Nothing
Set gChartData = Nothing
Set myChart = Nothing

End Sub

0 个答案:

没有答案