Search code examples
excelvbaexcel-addins

Constantly getting Err 1004 when trying to using Application.AddIns.Add


I'm trying to implement a bootstrap installer for my add-ins workbook, such that I can easily install the add-in for new users and send out updates. It works fine on my machine, but when having others test it, I get a runtime error when I try to call Set AI = Application.AddIns.Add(fileName:=fullPath, copyfile:=True). Specifically, the error is "1004: Unable to get the Add property of the AddIns class". I thought this was because the user needed to have "Trust access to the VBA project object model" enabled, but the error seems to occur even after they've toggled that box.

Other things I've checked:

  • The fullPath to the add-in is valid and the user can access the directory and the file
  • The user has the folder located at Application.UserLibraryPath

Any ideas?


Solution

  • Figured it out. It appears that the issue isn't one of permissions, but rather of whether a workbook is already open. Opening any workbook before running the Addins.Add prevented the error from occurring so I've simply added that into the program:

    If Application.Workbooks.Count = 0 then Set wb = Application.Workbooks.Add()
    
    Set AI = Application.AddIns.Add(fileName:=fullPath, copyfile:=True)
    
    If not wb is nothing then wb.Close