Link to home
Start Free TrialLog in
Avatar of John Carney
John CarneyFlag for United States of America

asked on

Copying a chart in Excel and pasting it in a specific place in a Powerpoint slide ?

I have a simple code that copies the chart and places it in the middle of the Powerpoint slide
Dim PPApp  As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
    Set PPApp = GetObject(, "Powerpoint.Application")
    ' Reference active presentation
    Set PPPres = PPApp.ActivePresentation
    PPApp.ActiveWindow.ViewType = ppViewSlide

    ThisWorkbook.Sheets(1).ChartObjects("Chart 3").CopyPicture
    With PPPres.Slides(2).Shapes.Paste
        .Align msoAlignCenters, True
        .Align msoAlignMiddles, True
    End With

Open in new window

My primary question is how do I specify the exact position at which to paste the chart? I came across some code that will do the positioning but I can't figure out how to adapt it:
Set oSlide = ActivePresentation.Slides(lCurrSlide)
Set oShape = oSlide.Shapes.Paste
oShape.top = 10
oShape.Left = 10
oShape.Width = 282
oShape.Height = 192

Open in new window

Eventually I would also like to open the presentation based on these parameters but first I want to get the positioning done.

Thanks,
John
Avatar of John Carney
John Carney
Flag of United States of America image

ASKER

I found some much simpler code that will position the chart exactly where I want it but it requires knowing the chart/picture's name in advance. How do I customize it so that it positions the newly pasted shape no matter what its name is?
PPPres.Slides(2).Shapes("Picture 19").top = 74
PPPres.Slides(2).Shapes("Picture 19").Left = 410

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of John Carney
John Carney
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Good work, John. If I do say so myself! :- )