2015-04-17 88 views
2

我每個月都會生成幾個Powerpoint文件,這些文件有幾個圖表,其中嵌入了Excel表格,有些月份某些系列(列)充滿了零,我想要找到一個Powerpoint宏,進入每個圖表外觀嵌入式excel中,並刪除全部爲零的列。Powerpoint VBA刪除空列?

現在我的代碼做在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表格behing他們。

很多謝謝

+0

您需要使用powerpoint中的excel對象。 –

回答

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