Using VBA to copy a Chartsheet to Powerpoint
Here is an example that I use...
Option Explicit
Private PPApp As PowerPoint.Application
Private PPPres As PowerPoint.Presentation
Private PPSlide As PowerPoint.Slide
Private PPShape As PowerPoint.Shape
Private sCnt&
Private chartWS As Chart
Private chartWB, dataWB As Workbook
Public Sub pptMacro()
Dim CheckStr$, dataDir$
Set chartWB = Application.ThisWorkbook
Set chartWS = ActiveSheet
chartWB.Sheets(chartWS.Name).CopyPicture Appearance:=xlPrinter,
Format:=xlPicture
Call openPPT
Call paste2PPT
Call closePPT
ThisWorkbook.Activate
Sheets(chartWS.Name).Activate
Exit Sub
no_data:
Call closePPT
End Sub
Private Sub openPPT()
Set PPApp = CreateObject("Powerpoint.Application.11")
PPApp.Activate
PPApp.Presentations.Open ThisWorkbook.Path & "\Template
\template.ppt"
With PPApp.ActivePresentation
.SaveAs ThisWorkbook.Path & "\the_new_file_name.ppt"
End With
End Sub
Private Sub closePPT()
'set to normal view before save/close
PPApp.ActiveWindow.ViewType = ppViewNormal
With PPApp.ActivePresentation
.Save
.Close
End With
PPApp.Quit
Set PPShape = Nothing
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing
End Sub
Private Sub paste2PPT()
' Paste chart
With PPApp.ActiveWindow
.ViewType = ppViewSlide
.View.Paste
End With
' Align pasted chart
sCnt = PPApp.ActiveWindow.Selection.SlideRange.Shapes.Cou nt
Set PPShape = PPApp.ActiveWindow.Selection.SlideRange.Shapes(sCn t)
PPShape.Select
PPShape.ZOrder msoSendToBack 'by sending to the back it now
becomes index:=1
PPApp.ActiveWindow.Selection.Unselect
End Sub
HTH—Lonnie
On Jun 2, 4:45*pm, MMD wrote:
I have written code for users to specify a worksheet and range or named range
that is then copied to PowerPoint Slides. *
For example: If a Chart is on a Sheet named "Revenue" and in cells B4:T64,
the user just adds "Revenue" and "B4:T64". *It works the same if the range of
cells are named.
This works fine for Charts embedded in a worksheets but if a Chart is on a
Chartsheet I don't have a range or name to reference. *I thought it was just
Chart1, Chart2, etc. but that doesn't seem to work.
Thanks!
|