Load and Unload of Addin Error

  • Hello All,


    Its been sometime since I have been involved here and I have an issue with the loading and unloading of an addin I think.


    The code is fired on the host template file to load the add-in as such.


    Code
    1. Private Sub Workbook_Open()
    2. AddIns("Be").Installed = True
    3. Application.Run ("BE.xlam!WBopen")
    4. End Sub



    And subsequently unload the application on closing of the document as such:


    Code
    1. Private Sub Workbook_BeforeClose(Cancel As Boolean)
    2. Application.Run ("BE.xlam!WBbeforeclose")
    3. AddIns("Be").Installed = False
    4. End Sub




    Once it passes into the application it hangs up at the first statement with a "Run-Time Error '9' Subscript out of Range" error.


    If I disable the load and unload features and just leave the addin installed, I have no issues and everything runs fine. It appears that once I have the installed false and true feature, it just hangs up.


    Any thoughts to this? (If I use On Error Resume Next throughout all the code, it ultimatly works, but I am not sure if that is an appropriate solution).

  • Re: Load and Unload of Addin Error


    This is very odd. I have gotten it to work randomly, without revising the code either. It somehow "times out" or somehow convinces itself that the addin is installed, yet its not.

  • Re: Load and Unload of Addin Error


    To not leave this issue hanging, I resolved it by "opening" the addin as opposed to having it preloaded and installing on opening. Still not sure why there is such an issue with the standard "installed = False or True" but its just to unstable to continue with.


    Code
    1. Private Sub Workbook_Open()
    2. Workbooks.Open Filename:="P:\Timesheets\Template\Module Standard\BE.xlam"
    3. Application.Run ("BE.xlam!WBopen")
    4. End Sub


    and


    Code
    1. Private Sub Workbook_BeforeClose(Cancel As Boolean)
    2. Application.Run ("BE.xlam!WBbeforeclose")
    3. On Error Resume Next
    4. Workbooks("BE.xlam").Close False
    5. End Sub