I have some code that when the workbook opens, checks to see if an add-in is there, and depending on the scenario, downloads a copy from onedrive.
My issue is that on the initial running, it errors with a subscript out of range on the last add-in install line. If the user closes excel and reopens, then it installs without issue. Stranger, if I have them delete the add-in from the add-ins folder, it still installs fine when they open the workbook. It's always the initial running that flags the error. For now I've been putting an on error handler that instructs them to re-open excel when the initial install error triggers. Any ideas?
sUserName = Environ("username")
sSourceAddInPath = "C:\Users\" & sUserName & "\xxxxxxxxxx\Excel\MyAddIn.xlam"
sDestinationAddInPath = Application.UserLibraryPath & "MyAddin.xlam"
'Add-in exists
If Dir(sDestinationAddInPath) <> "" Then
'Update if newer version available
If FileDateTime(sSourceAddInPath) > FileDateTime(sDestinationAddInPath) Then
FileCopy sSourceAddInPath, sDestinationAddInPath
End If
'No Add-in
Else
FileCopy sSourceAddInPath, sDestinationAddInPath
End If
AddIns("MyAddIn").Installed = True