View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
c1802362[_3_] c1802362[_3_] is offline
external usenet poster
 
Posts: 7
Default opening up Powerpoint slide from Excel

Hello

I'm running Excel 2003/Windows XP and am trying to get the following
to work:

I have a custom chart which is created from user input, after which
the user has the option of creating a powerpoint slide with a picture
of the chart on it.

Using John Peltier's late-binding code to create the chart picture and
push it to powerpoint, everything works fine - but only if a blank
powerpoint slide is already open. (I'm using late binding as I can't
expect my users to create a tool reference).

I'd like to allow the user to the option of opening a blank powerpoint
slide or an existing pre-formatted slide, without having the
Powerpoint app already open.

If I open Powerpoint ahead of launching the macro, everything works
fine. If Powerpoint is not open, I get runtime error 428 "ActiveX
component can't create object"

I tried substituting "Application.ActivateMicrosoftApp
xlMicrosoftPowerPoint" for the GetObject line (see ********* below),
but get an Error 91, "Object Variable Not set" at the next line
(annotated +++++++++ below). However, Powerpoint is launched and ready
to go.

Any suggestions?

Art

John Peltier's code:

Sub ChartToPresentation()
' Uses Late Binding to the PowerPoint Object Model
' No reference required to PowerPoint Object Library

Dim PPApp As Object ' As PowerPoint.Application
Dim PPPres As Object ' As PowerPoint.Presentation
Dim PPSlide As Object ' As PowerPoint.Slide

' Make sure a chart is selected
If ActiveChart Is Nothing Then
MsgBox "Please select a chart and try again.", vbExclamation, _
"No Chart Selected"
Else
' Reference existing instance of PowerPoint
Set PPApp = GetObject(, "Powerpoint.Application")
*********************
' Reference active presentation
Set PPPres = PPApp.ActivePresentation ++++++++++++++++++
PPApp.ActiveWindow.ViewType = 1 ' 1 = ppViewSlide
' Reference active slide
Set PPSlide = PPPres.Slides _
(PPApp.ActiveWindow.Selection.SlideRange.SlideInde x)

' Copy chart as a picture
ActiveChart.CopyPicture Appearance:=xlScreen, Size:=xlScreen, _
Format:=xlPicture

' Paste chart
PPSlide.Shapes.Paste.Select

' Align pasted chart
PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters,
True
PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles,
True

' Clean up
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing
End If

End Sub