将Excel图表发送到PowerPoint质量和大小

时间:2016-06-23 20:58:47

标签: excel vba powerpoint-vba

这是我将图表发送到特定位置的代码如下:

Sub This()


Dim PPApp  As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide

Set PPApp = New PowerPoint.Application
Set pptPres = PPApp.Presentations.Open("C:\Template.pptx")


Set PPApp = GetObject(, "Powerpoint.Application")
' Reference active presentation
Set PPPres = PPApp.ActivePresentation

' Copy the range as a picture
Sheets("Plots").ChartObjects("Chart Name").Copy
' Paste the range
With PPPres.Slides(10).Shapes.PasteSpecial
        ' Align pasted chart
        .Align msoAlignCenters, True
        .Align msoAlignMiddles, True
End With

End Sub

所以这就是假设它打开一个特定的PowerPoint幻灯片并将图表发送到幻灯片10.我的问题是,有没有办法将绘图发送到特定位置并使其达到一定的大小?

2 个答案:

答案 0 :(得分:1)

Adam,尝试以下代码,与我在PC上完成的测试一起使用。

根据我在最后4行中输入的值修改了图表的位置和大小。

Sub This()

    Dim PPApp  As PowerPoint.Application
    Dim PPPres As PowerPoint.Presentation
    Dim PPSlide As PowerPoint.Slide

    Set PPApp = New PowerPoint.Application
    Set pptPres = PPApp.Presentations.Open("C:\Template.pptx")

    ' Reference active presentation
    Set PPPres = PPApp.ActivePresentation

    ' Copy the range as a picture
    Worksheets("Plots").ChartObjects("Chart Name").Copy

    Set PPSlide = PPApp.ActivePresentation.Slides(10)

    ' Paste the Chart
    With PPSlide.Shapes.PasteSpecial
        .Top = 100
        .Left = 120
        .Height = 200
        .Width = 400
    End With

End Sub

答案 1 :(得分:0)

Sub This()


Dim PPApp  As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide

Set PPApp = New PowerPoint.Application
Set pptPres = PPApp.Presentations.Open("C:\Template.pptx")


Set PPApp = GetObject(, "Powerpoint.Application")
' Reference active presentation
Set PPPres = PPApp.ActivePresentation

' Copy the range as a picture
Sheets("Plots").ChartObjects("Chart Name").Copy
' Paste the range
With PPPres.Slides(10).Shapes.PasteSpecial
        ' Align pasted chart
        .Top = 100.84976
        .Left = 85.98417
        .Height = 120.7964
        .Width = 546.5262
End With

End Sub

PasteSpecial具有.Top .Left等特征。因此,这些可用于对齐和调整照片大小。我还注意到,如果您使用Paste而非PasteSpecial,那么照片质量会更差。