Object Variable question

I

ibeetb

I am trying to determine if an object variable (application) exists. If it
doesn't, I want to CreateObject, if it does, I want to GetObject....but I
keep gettting the object variable doesn't exist error whenever the code gets
to the "If ppApp is Nothing" part. Please see below.....

Dim ppApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide

If ppApp Is Nothing Then
Set ppApp = CreateObject("Powerpoint.Application")
With ppApp
.Visible = msoTrue
.WindowState = ppWindowMaximized
Set PPPres = ppApp.Presentations.Open("C:\Documents and
Settings\My Documents\IBSTest.ppt")
End With
Else
Set ppApp = GetObject(, "Powerpoint.Application")
End If
 
T

Tom Ogilvy

Something like this should work.

Dim ppApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
On Error Resume Next
Set ppApp = GetObject(, "Powerpoint.Application")
On Error goto 0
If ppApp Is Nothing Then
Set ppApp = CreateObject("Powerpoint.Application")
End If
With ppApp
.Visible = msoTrue
.WindowState = ppWindowMaximized
Set PPPres = ppApp.Presentations.Open( _
"C:\Documents and Settings\My Documents\IBSTest.ppt")
End With
 
B

Bob Phillips

That's odd, it works for me, although it creates a PPT object every time. As
you don't do anything to ppApp it will always be Nothing, so it will always
create not Get.

I don't get the error you get, an d looking at the code, would not expect
it.
 

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