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