导出到 PowerPoint 时更改 VBA 中的图表大小

Changing chart size in VBA when exporting to power point

我正在尝试使导出的图表在 powerpoint 幻灯片上变大,但让 运行 陷入循环问题。有什么想法吗?

Sub Export_Worksheet()

    Dim PPTApp As PowerPoint.Application
    Dim PPTPres As PowerPoint.Presentation
    Dim PPTSlide As PowerPoint.Slide
    Dim PPTShape As PowerPoint.Shape
    Dim SldIndex As Integer

    Dim Chrt As ChartObject
    
    Set PPTApp = New PowerPoint.Application
        PPTApp.Visible = True

    Set PPTPres = PPTApp.Presentations.Add

    SldIndex = 1

    For Each Chrt In ActiveSheet.ChartObjects

        Chrt.Copy
    
        Set PPTSlide = PPTPres.Slides.Add(SldIndex, ppLayoutBlank)
            PPTSlide.Shapes.Paste

        SldIndex = SldIndex + 1
        
    Next Chrt

End Sub

检查此代码。这是可行的,如果您需要在一张幻灯片上复制一个图表,更改图表的大小和位置,然后对下一张幻灯片重复操作

Sub Export_Worksheet()
    Dim PPTApp As PowerPoint.Application
    Dim PPTPres As PowerPoint.Presentation
    Dim PPTSlide As PowerPoint.Slide
    Dim PPTShape As PowerPoint.Shape
    Dim SldIndex As Integer

    Dim Chrt As ChartObject
    
    Set PPTApp = New PowerPoint.Application
        PPTApp.Visible = True

    Set PPTPres = PPTApp.Presentations.Add

    SldIndex = 1

    For Each Chrt In ActiveSheet.ChartObjects

        Chrt.Copy
    
        Set PPTSlide = PPTPres.Slides.Add(SldIndex, ppLayoutBlank)
            PPTSlide.Shapes.Paste
        With PPTPres.Slides(SldIndex).Shapes("Chart 1")
            .Top = 170
            .Left = 530
            .Height = 250
            .Width = 400
        End With
        SldIndex = SldIndex + 1
        
    Next Chrt

End Sub