CreateObject times out?

  • Thread starter Thread starter C Williams
  • Start date Start date
C

C Williams

Hi,

I am having some problems with CreateObject and Powerpoint. I'm working
from VB.NET with Powerpoint 2003.

The code below is only ever called when powerpoint is already open.
It's called when the user excecutes an action on a smart tag.

Almost always, GetObject fails, which causes CreateObject to be called.
At that point, PPT locks (can't do anything but move mouse) for ~30
seconds, before two message boxes pop up. The order is always the same
and is clearly important. The first is from my catch block ("Create
Error: Cannot create ActiveX component"), and the second box immediately
follows, reading "Powerpoint can't be used as a server because a dialog
box is open. Please close open dialog boxes to continue."

If the action is called again, GetObject is always successful. Very
occasionally (5% of the time?) GetObject succeeds the first time it is
called and I don't have the problem.

I have discovered that if I include a second CreateObject call in the
final catch block (after my msgbox), it will succeed. However, the
30-second wait for the first one to time out is not really acceptable
from a performance standpoint, so I need to find a way to prevent that
from happening in the first place!

What is happening, and how can I fix it? I appreciate any insight you have.

Thanks!

-Casey

Try

Try
'try to use GetObject
pptApp = DirectCast(GetObject(, "Powerpoint.Application"),
PowerPoint.Application)
MsgBox("it worked!")
Catch newEx As Exception
MsgBox("Get Error: " & vbCrLf & newEx.Message)
'if GetObject fails, try CreateObject
pptApp = DirectCast(CreateObject("Powerpoint.Application", ""),
PowerPoint.Application)
End Try

Catch ex As Exception
MsgBox("Create Error:" & vbCrLf & ex.Message)
End Try

'do stuff with pptApp here
 
Casey,
I've run into this before and never did find a way to solve it.

But I did find a workaround that works everytime.

The first failure creates a trappable error so I throw in an On Error
goto errHandler line just before the error creating line.

In errHandler I have a Case Select routine for the various error
values. In this error value I have a counter from 1 to 4 set to Resume
at the CreateObject line and rerun it. I set the counter to 4 so that
if I get there I can get out of the loop, even if it is unsuccessful,
I'm out and can try to deal with it another way.

Oddly enough, and I can't explain this, I've never had the counter
ever hit 3. The CreateObject line always worked on the second try.

I originally encountered this in Office 97 and still use the same
simple routine in everything I still do and haven't taken it out for
testing since so I don't know if it was Office 97 specific or just
some funky PPT thing.

Brian Reilly, PowerPoint MVP
 
Thanks for your input, Brian. It's good to hear at least that someone
else has encountered the same thing. I still haven't found the silver
bullet solution either. I guess that's why we invent workarounds...

Thanks!

-Casey
 

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

Back
Top