Creating new Powerpoint object and opening

S

simonc

There are several threads about opening a powerpoint presentation from an
Excel macro, and my syntax seems to follow these. However the code below
(which is just the start of the macro) works if the presentation is already
open in powerpoint but fails with the message

Presentations (unknown member) : Invalid request. The PowerPoint Frame
window does not exist.

at the line marked with '***** if there is no powerpoint application open.

Very grateful if anyone can point out where I'm going wrong. I'm using
Office 2000 and Windows XP Pro SP2.

CODE:

Dim oPPTApp As PowerPoint.Application
Dim oPPTShape As PowerPoint.Shape
Dim oPPTFile As PowerPoint.Presentation
Dim SlideNum As Integer
Sub Extract_slide_title_list()
Dim ppt_file As Variant
ppt_file = Application.GetOpenFilename("Powerpoint files (*.ppt),*.ppt",
, "Select Powerpoint file")
If ppt_file = False Then
Debug.Print "No file name entered. Programme exiting..."
response = MsgBox("No file name entered. Programme exiting...",
vbExclamation, "Warning")
End
End If

'Look for existing instance of Powerpoint
On Error Resume Next
Set oPPTApp = GetObject(, "PowerPoint.Application")
Set oPPTFile = oPPTApp.Presentations(ppt_file)
On Error GoTo 0
'Create new instance if no instance exists
If oPPTApp Is Nothing Then
Set oPPTApp = CreateObject("PowerPoint.Application")
Set oPPTFile = oPPTApp.Presentations.Open(ppt_file) '**********
End If
oPPTApp.Visible = msoTrue
 
J

Jon Peltier

Check out "Example 3: Using Active PowerPoint Objects if They Exist" on this
page:

http://peltiertech.com/Excel/XL_PPT.html

I suspect the problem is that Ppt must be visible before opening a
presentation.; I know there's something you have to do in order to do
anything in an invisible instance of PowerPoint, though I haven't used it in
a couple of years.

- Jon
 
S

simonc

Your intuition is wonderful. I moved the line oPPTApp.Visible = msoTrue to
before the Open statement and it worked!

One thing puzzles me. If I run my macro with no Powerpoint instance open and
the macro creates one and opens the file, and then I close Powerpoint
manually and run the macro again it fails. Something must get set internally
when it has to create a new Powerpoint application which remains set even if
you close Powerpoint manually.
 
J

Jon Peltier

Are your variables declared within the subroutine that uses them? If not,
they should be. How does the macro fail in this scenario?
/sig
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top