PowerPoint in VB.NET Issues

Posted on 2009-02-18
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
    LVL 59

    Accepted Solution

    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

    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
    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?


    Author Comment

    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
    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

    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

    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

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    Background   Certain code in VBA requires initialization, such as application events. The app initialization is often triggered by the Auto_Open sub which is a special procedure that runs when an add-in loads. More significantly, this sub does n…
    This video teaches viewers how to add transitions to their Slideshows and how to set up timing for the transitions.
    This video teaches viewers how to fit pictures into slides, crop and remove backgrounds, and alter photos to look more professional.

    733 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

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now