none
programatically closing an addin RRS feed

  • Question

  • Hello

    Using VB.net I currently programmatically open a few .xlsm workbooks. One of them references one personal .xlam addin.

    Program runs nice. To finish I kill all pointers to Excel classes and close all workbooks programmatically.

    I use the VBA window of Excel to check that all .xlsm Workbooks are indeed closed. However the .xlam addin remains.

    Using VBA immediate window and the command "Application.addins2.count" I can see that my personnal addin is the last of the list of addins. Need to use function addins2 and not addins.

    How can I close my .xlam so that Excel can in turn be closed nicely (right now I kill the process).

    Please note that Application.quit does not terminate the running Excel process but results in an unnamed Excel process in the system processes.

    I hope the previous is clear

    I thank in advance anybody who can shed some light on this small problem

    Saturday, July 20, 2019 8:16 AM

Answers

  • JMB,

    We are back to my original post...

    Read this:  https://support.microsoft.com/en-us/help/317109/office-application-does-not-exit-after-automation-from-visual-studio-n
    (also applies to vb.net - all editions)

    The original article (for vba) kb199219 is no longer available.
    ("Automation Doesn't Release Excel Object From Memory")
    Deals with orphan objects left behind.


    '---
    Special Sort Excel add-in (20+ new ways to sort)
    (also other workbooks and add-ins
    Download from MediaFire...
    http://www.mediafire.com/folder/lto3hbhyq0hcf/Documents

    Saturday, July 20, 2019 3:55 PM
  • Thank you for this clarification. Very clear article.

    Unfortunately I found it not practical to release all the Excel objects. I tried hard some time ago but gave up as coding effort was huge. I don't believe this is something the user should do. There should be a way to release all RCWs in one system call.

    Therefore I keep the current method which is to kill the remnant Excel process (easily identifiable as it has an blank window title).

    I thank you again for your help

    • Marked as answer by JMB1502 Sunday, July 21, 2019 5:57 AM
    Sunday, July 21, 2019 5:57 AM

All replies

  • JMB,

    I don't do VBnet, but for what it is worth...

    if it was VBA, I would make sure in the add-in;
      that all userforms were unloaded.
      that all objects were set to nothing.

    Saturday, July 20, 2019 12:33 PM
  • The addin handles the ribbon, I dont think the problem is here.

    I was looking for something like application.addins(myaddin).remove or .close but this is not among the methods that can be applied to an addin.

    in VBA however I can do ThisWorkbook.close although the .xlam is not among the list of workbooks (Workbooks.count is zero at this stage)

    Saturday, July 20, 2019 3:01 PM
  • JMB,

    In vba, add-ins are excluded from the workbooks count.
    To close an add-in (vba), you can use...

        Excel.Workbooks("filename including extension").Close savechanges:=False
        (quote marks are required)

    [Edit added] - This also works...
        Excel.Workbooks("filename including extension").Close False

    Saturday, July 20, 2019 3:21 PM
  • Very good. This works. Thank you very much.

    Now VBA is blank after removing the addin.

    I send the oXLS.quit command from VB.net (oXLS points to the Excel app), sets oXLS to nothing and the Excel window disappears.

    However, the Excel process is still running (with blank in the window title) and I have to kill it (from VB.net). Process is not under my processes in task manager but I can kill it allright.

    Is there a way to avoid this last step ? shouldnt oXLS.quit terminate the Excel process ?

    Saturday, July 20, 2019 3:35 PM
  • JMB,

    We are back to my original post...

    Read this:  https://support.microsoft.com/en-us/help/317109/office-application-does-not-exit-after-automation-from-visual-studio-n
    (also applies to vb.net - all editions)

    The original article (for vba) kb199219 is no longer available.
    ("Automation Doesn't Release Excel Object From Memory")
    Deals with orphan objects left behind.


    '---
    Special Sort Excel add-in (20+ new ways to sort)
    (also other workbooks and add-ins
    Download from MediaFire...
    http://www.mediafire.com/folder/lto3hbhyq0hcf/Documents

    Saturday, July 20, 2019 3:55 PM
  • Thank you for this clarification. Very clear article.

    Unfortunately I found it not practical to release all the Excel objects. I tried hard some time ago but gave up as coding effort was huge. I don't believe this is something the user should do. There should be a way to release all RCWs in one system call.

    Therefore I keep the current method which is to kill the remnant Excel process (easily identifiable as it has an blank window title).

    I thank you again for your help

    • Marked as answer by JMB1502 Sunday, July 21, 2019 5:57 AM
    Sunday, July 21, 2019 5:57 AM