我每个月都会生成几个Powerpoint文件,这些文件有几个图表,后面嵌入了excel表,有些月份有些系列(列)都是零,我想找到一个进入每个图表的Powerpoint宏查看嵌入式excel并删除全部为零的列。
现在我有了在excel中执行此操作的代码
Sub DeleteColumns()
Dim LR As Long, LC As Long
Dim i As Long, j As Long
LR = Cells.Find(What:="*", SearchDirection:=xlPrevious,SearchOrder:=xlByRows).Row
LC = 52
For j = LC To 1 Step -1
For i = LR To 1 Step -1
If Cells(i, j).Value = 0 Then
Columns(j).Delete
Exit For
End If
Next i
Next j
End Sub
它的工作原理,我只是不知道如何引用powerpoint中的所有图表,然后将嵌入的excel表作为目标。
非常感谢
答案 0 :(得分:0)
您可以公开所有基础Excel图表。
我不确定您是如何删除零列的,所以建议您在下面突出显示的位置添加此列。
Sub ChangeChartData()
Dim pptChart As Chart
Dim pptChartData As ChartData
Dim xlWorkbook As Object
Dim sld As Slide
Dim shp As Shape
For Each sld In ActivePresentation.Slides
For Each shp In sld.Shapes
If shp.HasChart Then
Set pptChart = shp.Chart
Set pptChartData = pptChart.ChartData
pptChartData.Activate
Set pptWorkbook = pptChartData.Workbook
'your delete code here
pptWorkbook.Close True
End If
Next
Next
Set pptWorkbook = Nothing
Set pptChartData = Nothing
Set pptChart = Nothing
End Sub