Microsoft Office Tutorials and References
In Depth Information
When completed, the macro will look like this, with comments that have been added to
explain each step:
‘This example assumes you have PowerPoint open,
‘with your destination presentation file open.
‘Declare variables for the PowerPoint application,
‘presentation filename, and Slide object.
Dim ppApp As Object, ppPres As Object, ppSlide As Object
‘For this example, you want to copy the first chart on your worksheet.
‘Select the chart by its index number one.
‘Establish the identity of the open PowerPoint application.
Set ppApp = GetObject(, “Powerpoint.Application”)
‘Establish the identity of the open PowerPoint presentation.
Set ppPres = ppApp.ActivePresentation
‘Establish a reference to the next available slide.
Set ppSlide = ppPres.Slides(ppApp.ActiveWindow.Selection.SlideRange.SlideIndex)
‘Copy the selected chart.
ActiveChart.CopyPicture Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture
‘Paste the chart into the PowerPoint slide.
‘Align the range picture to be centered in the slide.
.Align msoAlignCenters, msoTrue
.Align msoAlignMiddles, msoTrue
‘Deselect the selected chart.
‘Release system memory reserved for the Object variables.
Set ppApp = Nothing
Set ppPres = Nothing
Set ppSlide = Nothing
Press Alt+Q to return to the worksheet. Press Alt+F8 to show the macro dialog box, and test
the macro by selecting the macro name and clicking the Run button.