【问题标题】:Changing chart size in VBA when exporting to power point导出到 power point 时更改 VBA 中的图表大小
【发布时间】:2021-09-23 16:56:43
【问题描述】:

我正在尝试在 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

【问题讨论】:

    标签: vba export powerpoint


    【解决方案1】:

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

    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
    
    

    【讨论】:

    • 这会中断循环并运行到“运行时错误 2147188160 (80048240) 自动化错误”
    • 可以准确计算出图名PPTSlide.Shapes.Paste For Each j In PPTPres.Slides(SldIndex).Shapes localName = j.Name Next
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-19
    • 1970-01-01
    • 2016-09-12
    • 1970-01-01
    • 2016-11-22
    • 2010-09-27
    相关资源
    最近更新 更多