简体   繁体   中英

Excel VBA install add-in

I use this code to install an Add-in. But it does not seem to enable it. I get this error message:

Runtime error 1004: Unable to set the installed property of the add-in class.

My code:

Sub installatie_Click()

    Dim AI As Excel.AddIn
    Set AI = Application.AddIns.Add(Filename:="J:\Planning\Sjablonen\Updates\versieA.xlam")

    Application.AddIns("versieA").Installed = True
End Sub

I always use to make my adding able to self install. Please try this code (in addin Workbook_Open event of its ThisWorkbook module): Your file may have a problem... You have to set its Title ( BuiltinDocumentProperties(1) ). Manually, right click on the addin file and modify (only with adding closed) or programatically ( ThisWorkbook.BuiltinDocumentProperties(1) = "Whatever" ), but without spaces..

Private Sub Workbook_Open()
  Dim Name As String, tmp As Boolean, n As Boolean, Merk As String
   Name = ThisWorkbook.BuiltinDocumentProperties(1)
   On Error Resume Next
   tmp = AddIns(Name).Installed
    If Err.number <> 0 Then
      Err.Clear: On Error GoTo 0
         If Workbooks.Count = 0 Then n = True
             If n Then
                 Workbooks.Add
                 Merk = ActiveWorkbook.Name
             End If
             AddIns.Add Filename:=ThisWorkbook.FullName
             AddIns(Name).Installed = True
             If n Then Workbooks(Merk).Close False
    End If
    On Error GoTo 0
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM