Microsoft Office Tutorials and References
In Depth Information
Try It
3.
In the module you just created, type Sub CopyEmbeddedChart and press Enter. VBA will
automatically place a pair of empty parentheses at the end of the Sub line, followed by an
empty line, and the End Sub line below that. Your macro will look like this so far:
Sub CopyEmbeddedChart()
End Sub
4.
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
5.
For this example, you want to copy the first chart on your worksheet. Programmatically
select the chart by its index number 1:
ActiveSheet.ChartObjects(1).Select
6.
Establish the identity of the open PowerPoint application:
Set ppApp = GetObject(, “Powerpoint.Application”)
7.
Establish the identity of the open PowerPoint presentation:
Set ppPres = ppApp.ActivePresentation
8.
Establish a reference to the next available slide:
Set ppSlide = ppPres.Slides(ppApp.ActiveWindow.Selection.SlideRange.SlideIndex)
9.
Copy the selected chart:
ActiveChart.CopyPicture Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture
10.
Paste the chart into the PowerPoint slide:
ppSlide.Shapes.Paste.Select
11.
Align the chart picture to be centered in the slide:
With ppApp.ActiveWindow.Selection.ShapeRange
.Align msoAlignCenters, msoTrue
.Align msoAlignMiddles, msoTrue
End With
12.
Deselect the selected chart:
Range(“A1”).Select
13.
Release system memory reserved for the Object variables:
Set ppApp = Nothing
Set ppPres = Nothing
Set ppSlide = Nothing
Search JabSto ::




Custom Search