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
    Private Sub Workbook_Open()
    AddIns("Be").Installed = True
    Application.Run ("BE.xlam!WBopen")
    End Sub



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


    Code
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Application.Run ("BE.xlam!WBbeforeclose")
    AddIns("Be").Installed = False
    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
    Private Sub Workbook_Open()
    Workbooks.Open Filename:="P:\Timesheets\Template\Module Standard\BE.xlam"
    Application.Run ("BE.xlam!WBopen")
    End Sub


    and


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

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!