none
Cannot close PowerPoint application through Add-In RRS feed

  • Question

  • Hi,

    i am developing a PowerPoint AddIn using VSTO which is updating some textfields in an unattending mode. Now i have following problem. PowerPoint application with an existing presentation is started from the command line for example from the Windows Task Scheduler. ("...\office14\powerpnt.exe C:\example.pptx") AddIn is loaded and also is doing it's job to update some textfields. Now comes the problem that i want to close the PowerPoint application through the AddIn after the textfields changes have been done.

    I tried ThisAddIn.Application.Quit() but nothing happens. When debugging in Visual Studio i get following Exception:
    System.Runtime.InteropServices.COMException (0x80048240): Application (unknown member) : Invalid request. This operation cannot be performed in this event handler.
    at Microsoft.Office.Interop.PowerPoint._Application.Quit()

    Also i tried Application.Exit(). Result was that there is no exception but the complete Apllication crashes.

    Any idea how to cleanly exit the PowerPoint application?

    Regards,
    Christoph
    Tuesday, January 22, 2013 11:01 AM

Answers

All replies

  • try to post Quit message instead of rising it directly. From main Ui thread (where event for your add-in is raised) do something like this:

    SynchronizationContext.Current.Post(s=> popwerPointApp.Quit(), null);

    Tuesday, January 22, 2013 12:08 PM
  • Thanks for the reply.

    Is there an equivalent code for VB.Net? I used vb.net.

    Tuesday, January 22, 2013 2:50 PM
  • SynchronizationContext.Current.Post(Function(s) powerPointApp.Quit(), Nothing)
    Tuesday, January 22, 2013 7:25 PM
  • Hi Christoph

    <<i am developing a PowerPoint AddIn using VSTO which is updating some textfields in an unattending mode. Now i have following problem. PowerPoint application with an existing presentation is started from the command line for example from the Windows Task Scheduler. ("...\office14\powerpnt.exe C:\example.pptx") AddIn is loaded and also is doing it's job to update some textfields.>>

    I can't help but wonder if an Add-in is the correct tool to use for unattended updating of content?

    Why wouldn't you work directly with the Office Open XML file, instead?


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, January 22, 2013 8:36 PM
    Moderator
  • Thx Damian,

    "SynchronizationContext.Current.Post(Function(s) powerPointApp.Quit(), Nothing)"
    I tried your solution but Post() expects a returned value from powerPointApp.Quit() but that function does not return something. The exactly error message in Visual Studio: Expression does not produce a value.
    I tried to use 
    SynchronizationContext.Current.Post(Sub(s) powerPointApp.Quit(), Nothing) but then i get a System.NullReferenceException: Object reference not set to an instance of an object.

    Hi Cindy,

    right, but the Add-in is not only used for updating some content. It has many other features for the user in editing mode.


    Wednesday, January 23, 2013 9:00 AM
  • i think you got something wrong - http://msdn.microsoft.com/en-us/library/system.threading.synchronizationcontext.post.aspx is a function that reutnrs void and expects delegate and object. Most probably my conversion to vb.net produced code that is not a proper vb.net code. Use sample code here http://www.vbforums.com/showthread.php?635629-RESOLVED-Updating-controls-via-SynchronizationContext-Class as reference and write proper code.
    Wednesday, January 23, 2013 12:15 PM
  • Thanks Damian,

    now it works fine.

    Friday, January 25, 2013 9:30 AM
  • Hi Christoph,

    Is it possible for you to share how you fixed this issue? I have a similar problem and very curious about how you solved it.

    Thanks in advance!

    Arne

    Wednesday, February 20, 2013 2:23 PM