Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General PowerPoint Questions / March 2008

Tip: Looking for answers? Try searching our database.

CreateObject vs New

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dR - 29 Feb 2008 15:15 GMT
Since PowerPoint is a single instance application, what is the
difference between:

Set oPPApp = New PowerPoint.Application

and

Set oPPApp = CreateObject("PowerPoint.Application")

Thanks
Steve Rindsberg - 29 Feb 2008 21:52 GMT
> Since PowerPoint is a single instance application, what is the
> difference between:
[quoted text clipped - 4 lines]
>
> Set oPPApp = CreateObject("PowerPoint.Application")

One fires off a new instance of PowerPoint and gives you a reference to it or
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
================================================
dR - 02 Mar 2008 13:50 GMT
> In article <ce89a735-0c52-4171-9ac5-50ddab7f1...@i29g2000prf.googlegroups.com>,
>
[quoted text clipped - 21 lines]
> 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
Chirag - 02 Mar 2008 17:21 GMT
>> In article
>> <ce89a735-0c52-4171-9ac5-50ddab7f1...@i29g2000prf.googlegroups.com>,
[quoted text clipped - 44 lines]
> 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
Steve Rindsberg - 02 Mar 2008 21:27 GMT
> >> In article
> >> <ce89a735-0c52-4171-9ac5-50ddab7f1...@i29g2000prf.googlegroups.com>,
[quoted text clipped - 47 lines]
> You would want to close the PowerPoint instance that you started and not the
> one that you did not start.

I'd say the same thing but put it slightly differently:

If there's already an instance of PPT running, the user's doing something with
PPT already; you don't want to close PPT when you're done.  Otherwise, you know
that you created the instance, so it's fairly certain that it's ok to close it.

(If the user starts working with PPT while you're automating it, all bets are
off, of course)

In other words, you can't tell the difference between an instance you started
and one you did not once the instance is started, but if you find that there's
already an instance when you know you didn't create it, you can be sure it's
not yours.

So, you typically, would write code like this:

>     On Error Resume Next
>
[quoted text clipped - 21 lines]
>   PowerShow - View multiple PowerPoint slide shows simultaneously
>   http://officeone.mvps.org/powershow/powershow.html

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

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.