【问题标题】:Resizing chart in powerpoint after inserting it from excel (Excel VBA)从excel(Excel VBA)插入后在PowerPoint中调整图表大小
【发布时间】:2012-10-27 23:11:44
【问题描述】:

我有一些代码在 中获取图表并将其粘贴到 幻灯片中。但是,一旦将其粘贴到 中,我不确定如何调整图表的大小。我已经研究过它是哪个数字“形状”,我​​可以手动执行此操作,但我不知道如何自动执行此操作。任何帮助将不胜感激,谢谢!

这是我的代码:

Sub AddChartToPPT(PPT As PowerPoint.Application, Slide As Integer, Chart As String, FromTop As Double, FromLeft As Double, Length As Double, Width As Double)
Dim activeslide As PowerPoint.Slide
PPT.ActiveWindow.View.GotoSlide Slide
Set activeslide = PPT.ActivePresentation.Slides(Slide)
ActiveSheet.ChartObjects(Chart).Activate
ActiveChart.ChartArea.Copy
activeslide.Shapes.PasteSpecial(DataType:=ppPasteMetafilePicture).Select
PPT.ActiveWindow.Selection.ShapeRange.Left = FromLeft
PPT.ActiveWindow.Selection.ShapeRange.Top = FromTop
'Need to add scaling code
End Sub

【问题讨论】:

    标签: excel powerpoint powerpoint excel vba powerpoint


    【解决方案1】:

    试试这个:

    dim shp as Object
    set shp=activeslide.Shapes.PasteSpecial(DataType:=ppPasteMetafilePicture)
    shp.Left = FromLeft
    shp.Top = FromTop
    

    所以你的代码的其余部分:

    Sub AddChartToPPT(PPT As PowerPoint.Application, Slide As Integer, Chart As String, FromTop As Double, FromLeft As Double, Length As Double, Width As Double)
    Dim activeslide As PowerPoint.Slide, shp as Object
    PPT.ActiveWindow.View.GotoSlide Slide
    Set activeslide = PPT.ActivePresentation.Slides(Slide)
    ActiveSheet.ChartObjects(Chart).Activate
    ActiveChart.ChartArea.Copy
    set shp=activeslide.Shapes.PasteSpecial(DataType:=ppPasteMetafilePicture)
    shp.Left = FromLeft
    shp.Top = FromTop
    'Need to add scaling code     
    End Sub
    

    【讨论】:

    • 嗯,这似乎不起作用。此外,您的代码似乎解决了图表的位置(我已经有了),而不是图表的大小。
    • 我在“Set shp = activeslide.Shapes.PasteSpecial(DataType:=ppPasteMetafilePicture)”这一行得到类型不匹配
    • 将shp变量类型改为object并重试(我已经更新了答案)
    【解决方案2】:

    根据我的经验,在将图表对象粘贴到 PowerPoint 之前,在 Excel 中调整图表对象的大小会更容易。首先,Excel的对象模型更加清晰。其次,调整图元文件的大小可能会导致失真,而调整图表大小并粘贴为不需要调整大小的图元文件则不会。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-01
      • 1970-01-01
      • 2019-02-26
      相关资源
      最近更新 更多