CreateObject vs New

D

dR

Since PowerPoint is a single instance application, what is the
difference between:

Set oPPApp = New PowerPoint.Application

and

Set oPPApp = CreateObject("PowerPoint.Application")



Thanks
 
D

dR

One fires off a new instance of PowerPoint and gives you a reference to itor
gives you a reference to the already-running instance if one exists.

The other gives you a reference to the already-running instance of PPT if one
exists or fires off a new instance and gives you reference to it.

IOW, no real difference.

-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ:  www.pptfaq.com
PPTools:  www.pptools.com
================================================

If there is no real difference, and a new instance will be started as
necessary,is there any sense in testing for an existing instance?

I saw many users using code like this:

On Error Resume Next
Set oPPApp = GetObject(, "PowerPoint.Application")
On Error GoTo 0

If oPPApp Is Nothing Then
Set oPPApp = New PowerPoint.Application
Else
'** Do nothing. PowerPoint already exists.
End If

Is there any purpose to all this?

Thanks
dR
 
C

Chirag

dR said:
If there is no real difference, and a new instance will be started as
necessary,is there any sense in testing for an existing instance?

I saw many users using code like this:

On Error Resume Next
Set oPPApp = GetObject(, "PowerPoint.Application")
On Error GoTo 0

If oPPApp Is Nothing Then
Set oPPApp = New PowerPoint.Application
Else
'** Do nothing. PowerPoint already exists.
End If

Is there any purpose to all this?

Thanks
dR

You would want to close the PowerPoint instance that you started and not the
one that you did not start. So, you typically, would write code like this:

On Error Resume Next

bNewPPApp = False
Set oPPApp = GetObject(, "PowerPoint.Application")

If oPPApp Is Nothing Then
bNewPPApp = True
Set oPPApp = New PowerPoint.Application
End If

In close routine:

If bNewPPApp Then
oPPApp.Quit
End If

Also, for the instance that you started and user opened a new presentation
in it, you don't want to close that instance too. Check for presentations
that exist and were not opened by your app in PowerPoint before closing that
instance of PowerPoint.

- Chirag

PowerShow - View multiple PowerPoint slide shows simultaneously
http://officeone.mvps.org/powershow/powershow.html
 

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