Excel VBA - 批量图表导出到ppt

时间:2017-12-28 23:01:35

标签: excel vba excel-vba powerpoint powerpoint-vba

我和previously描述的问题非常类似,但在我的情况下,我想将所有图表一次性导出为我的ppt模板幻灯片的特定占位符。 对于总出口,我使用从网上抓取的以下解决方案。如何直接粘贴这些图表?不知何故,上述解决方案对我来说不起作用。 我很感激任何建议

选项明确

Sub TotalExport_chart_to_ppt()

' Set a VBE reference to Microsoft PowerPoint Object Library

Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
Dim SlideCount As Long
Dim ws As Worksheet
Dim oChrtObj As ChartObject
Dim nPlcHolder As Long

' Reference existing instance of PowerPoint
Set PPApp = GetObject(, "Powerpoint.Application")

' Reference active presentation
Set PPPres = PPApp.ActivePresentation

PPApp.ActiveWindow.ViewType = ppViewSlide

' loop through each worksheet within the active workbook
For Each ws In Worksheets
    ' loop through each chart object on current worksheet
    For Each oChrtObj In ws.ChartObjects
        ' copy chart as chartobject
        oChrtObj.Copy
        ' Add a new slide and paste in the chart
        SlideCount = PPPres.Slides.Count
        Set PPSlide = PPPres.Slides.Add(SlideCount + 1, ppLayoutChart)
        With PPSlide.Shapes.Paste
            .Align msoAlignCenters, True
            .Align msoAlignMiddles, True
        End With
    Next oChrtObj
Next ws

' Clean up
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing
Set ws = Nothing
Set oChrtObj = Nothing

End Sub

1 个答案:

答案 0 :(得分:0)

它可能有助于pastespecial然后设置格式

Set PPShape = PPSlide.Shapes.PasteSpecial(DataType:=ppPasteEnhancedMetafile)

还有其他类型的专辑,因此您必须决定图表的内容。