Adam Warner
Adam Warner

Reputation: 1354

Sending Excel Chart To PowerPoint Quality And Size

This is the code that I have for sending charts to a specific location is the following:

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

So this does what it is suppose to it opens up a specific PowerPoint slide and sends the chart to slide 10. My question is, is there a way to send the plot to a specific location and make it a certain size?

Upvotes: 1

Views: 886

Answers (2)

Shai Rado
Shai Rado

Reputation: 33682

Adam, try the following code, works well with the tests I've done on my PC.

The chart location and size were modified according to the values I've entered in the last 4 lines I added.

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

Upvotes: 1

Adam Warner
Adam Warner

Reputation: 1354

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 has the characteristics of having .Top .Left and so on. So those can be used to align and resize the photo. I also noticed that if you use Paste and not PasteSpecial then the photo quality is worse.

Upvotes: 0

Related Questions