Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


PowerPoint in VB.NET Issues

Posted on 2009-02-18
Medium Priority
Last Modified: 2013-11-17
I am attempting to run a chunk of code that takes an array of selected slide indexes, and recreate a new slide deck using only the slides selected in the order selected by the user.  once this is done, ultimately I convert the new Slide Deck into a SWF file.  I am running into an issue running multiple instances of perpoint at the same time.  If run individually, I am sucessful.  But if I open another instance at the same time, it errors out at various points when a conflit occurs.  This is a server based application, so the Powerpoint would be running on the server and the result is downloaded from the web.  Office doesnt need to be installed on the user's machine.

Bonus issue 1:  How can i determine if an instance of Powerpoint is already running on the server?

Bonus Issue 2:  How can I close Powerpoint from this code?  objPPT.quit() doesnt work.
Sub convertPPTtoSWF()
        ' Create temporary array to loop through
        Dim arrSlides(2) As Integer
        arrSlides(0) = 2
        arrSlides(1) = 6
        arrSlides(2) = 4
        ' Open Powerpoint
        Dim objPPT As New PowerPoint.Application
        objPPT.Visible = MsoTriState.msoTrue
        objPPT.WindowState = PowerPoint.PpWindowState.ppWindowMinimized
        objPPT.ShowWindowsInTaskbar = MsoTriState.msoFalse
        ' Open Original Powerpoint Slide Deck, Save as TempOrig and TempNew, Close
        Dim objPres As PowerPoint.Presentation
        Dim varTimeStamp As String
        objPres = objPPT.Presentations.Open("c:\PPT\Test.ppt")
        varTimeStamp = Date.Now.Hour.ToString & Date.Now.Minute.ToString & Date.Now.Second.ToString & Date.Now.Millisecond.ToString
        objPres.SaveCopyAs("c:\PPT\" & varTimeStamp & "-Orig.ppt")
        objPres.SaveCopyAs("c:\PPT\" & varTimeStamp & ".ppt")
        ' Open Temp PowerPoint Slide Deck and delete all slides (Maintains Master)
        Dim objTempPres As PowerPoint.Presentation
        objTempPres = objPPT.Presentations.Open("c:\PPT\" & varTimeStamp & ".ppt")
        Dim objSlide As PowerPoint.Slide
        Do While objTempPres.Slides.Count > 0
            objSlide = objTempPres.Slides(1)
        Dim i As Integer
        Dim intNum As Integer
        ' Move desired slides from Original to Temp Deck
        Do While i < arrSlides.Length
            intNum = arrSlides(i)
            objTempPres.Slides.InsertFromFile("c:\PPT\" & varTimeStamp & "-Orig.ppt", objTempPres.Slides.Count, intNum, intNum)
            i += 1
        ' Save Temp Deck and Close Powerpoint
        ' Convert the Temp Deck
        Dim converter As New iSpring.PresentationConverter
        converter.OpenPresentation("c:\PPT\" & varTimeStamp & ".ppt")
        converter.GenerateFlash("C:\PPT\", varTimeStamp & ".swf", iSpring.OutputMode.OM_SOLID, "NavigationPanel", "")
        File.Delete("c:\PPT\" & varTimeStamp & ".ppt")
        File.Delete("c:\PPT\" & varTimeStamp & "-Orig.ppt")
    End Sub

Open in new window

Question by:kova4
  • 3
  • 3
LVL 59

Accepted Solution

Chris Bottomley earned 1500 total points
ID: 23674708
Normal mechanism to to check for an existing instance:

    On Error Resume Next
    Set pptApp = GetObject(, "POWERPOINT.APPLICATION")
    On Error GoTo 0
    If pptApp Is Nothing Then _
        Set pptApp = CreateObject("POWERPOINT.APPLICATION")

quit ought to work as soon as the calling application itself terminates, are you saying this doesn't happen.  Note explicitly after sending quit the ppt app stays open until the code that opened / connected to it terminates.


Author Comment

ID: 23681363
It is a web application.  So the Quit command doesnt close the app.  I can kill the process sucessfully, but that would kill all instances of the program making it a bit difficult to have concurrent users running at the same time.

If a quit command isnt feasible, how can I at least open the application to have multiple users running concurrently without stepping on each other's toes?  Is there a process to open multiple threads of Powerpoint?
LVL 59

Expert Comment

by:Chris Bottomley
ID: 23681605
I am unable and unskilled in re running as web apps ... but that will not stop me having an opinion :o)

From my earlier checks PPT 2003 seems to open multiple instances, haven't tested 2007 so to help with the thought processes, what version of ppt is in use?

i.e. if you can test for multiple occurences then you can avoid killing the process and if only one then kill it.  Might that work as a kludge?

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.


Author Comment

ID: 23681782
Its PowerPoint 2007, so only one window get opened, and only one Process gets generated.  Do you know of a way to force an application that works only in one instance to open in multiple?  This would be the workaround I need.
LVL 59

Assisted Solution

by:Chris Bottomley
Chris Bottomley earned 1500 total points
ID: 23690151
By design it seems PPT only opens as a single instance, and this is the case with 2003 and 2007.  I have only heard of a single workaround which is here:


LVL 21

Expert Comment

ID: 23695048
Since all you're doing is pulling in the selected slides and creating a Flash presentation I recommend that you save the slides as individual images in the first place.  This would allow you complete control of the application and remove the PowerPoint equation.

BTW, PowerPoint is a single instance app and I'm pretty sure that trying to run multiple instances from a server is a licensing violation.  However, having said that, you might get by with it if you set it up as a terminal server and everyone logs onto it as a sperate user.

Author Closing Comment

ID: 31548435
Thank you so much for your help.  These solutions will work for this instance!  I was made aware of another route to take that uses a software solution to bypass PowerPoint called Aspose.  it does everything I need.  But thank you again for all your help!

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This video teaches viewers how to add simple and professional themes to their slides.
This video teaches viewers how to add transitions to their Slideshows and how to set up timing for the transitions.
Suggested Courses
Course of the Month14 days, 1 hour left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question