Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default Object Variable question

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Object Variable question

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



--
Regards,
Tom Ogilvy

"ibeetb" wrote in message
...
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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Object Variable question

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.

--
HTH

-------

Bob Phillips
"ibeetb" wrote in message
...
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




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Runtime Error '91' Object variable or With block variable not set Alec Coliver Excel Discussion (Misc queries) 2 October 24th 09 02:29 PM
Object Variable Not Set Error on Selection object Jean Excel Worksheet Functions 3 July 24th 06 06:45 PM
Cells.Find error Object variable or With block variable not set Peter[_21_] Excel Programming 2 May 8th 04 02:15 PM
Pivot Table - Object variable or with block variable not set? George Nicholson[_2_] Excel Programming 1 April 16th 04 09:12 PM
Error 91 - Object variable with block variable not set Jim[_35_] Excel Programming 2 November 27th 03 03:34 AM


All times are GMT +1. The time now is 11:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"