问题遇到的现象和发生背景
VBA 在路径下的ppt中创建图表 并更新数据。想在这之前判断,如果存在该图表则删除,不知道该怎么写,找不到资料
问题相关代码,请勿粘贴截图
Dim shp_04 As PowerPoint.shape
Dim chartsheet_04 As Worksheet
Dim arr1_04()
Dim sourceaddress_04 As String
sourceaddress_04 = wb.Sheets("ppt_page4_01").Range("a1:m5").Address
arr1_04 = Range(sourceaddress_04).Value
'Dim chart As PowerPoint.chart
'For Each chart In ppt.Slides(4)
' If Left$(chart.Name, 6) = "Object" Then
' chart.Delete
' End If
'Next chart
Set shp_04 = ppt.Slides(4).Shapes.AddChart(xlColumnStacked, 40, 100, 880, 200)
Set chartsheet_04 = shp_04.chart.ChartData.Workbook.Worksheets(1)
chartsheet_04.Cells.clear
chartsheet_04.[a1].Resize(UBound(arr1_04), UBound(arr1_04, 2)) = arr1_04
’shp_04.chart.SetSourceData Source:=wb.Sheets("ppt_page4_01").Range("a1:m5"), PlotBy:=xlRows ‘为什么这么写会报错
shp_04.chart.SetSourceData Source:="='sheet1'!" & sourceaddress_04, PlotBy:=xlRows
shp_04.chart.Axes(xlCategory).TickLabels.Font.Size = 10
shp_04.chart.Axes(xlValue).TickLabels.Font.Size = 10
shp_04.chart.Legend.Font.Size = 8
shp_04.chart.ChartData.Workbook.Close
wb.Close
End Sub