Microsoft Office Tutorials and References
In Depth Information
Try It
When completed, the macro will look like this, with comments that have been added to
explain each step:
Sub CopyEmbeddedChart()
‘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.
With ppApp.ActiveWindow.Selection.ShapeRange
.Align msoAlignCenters, msoTrue
.Align msoAlignMiddles, msoTrue
End With
‘Deselect the selected chart.
‘Release system memory reserved for the Object variables.
Set ppApp = Nothing
Set ppPres = Nothing
Set ppSlide = Nothing
End Sub
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.
To view the video that accompanies this lesson, please select Lesson 30, available
at the following website: .
Search JabSto ::

Custom Search