Excel VBA安装加载项

问题描述 投票:0回答:1

我使用此代码来安装外接程序。但是它似乎没有启用它。我收到此错误消息:

运行时错误1004:无法设置外接程序的安装属性课。

我的代码:

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
excel vba excel-addins
1个回答
0
投票

我总是使自己的添加程序能够自行安装。请尝试以下代码(在其Workbook_Open模块的插件ThisWorkbook事件中):您的文件可能有问题...您必须设置其标题(BuiltinDocumentProperties(1))。手动右键单击外接程序文件,然后进行修改(仅在关闭状态下进行添加)或以编程方式进行修改('hisWorkbook.BuiltinDocumentProperties(1)=“随便”),但不能有空格。.]]

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
© www.soinside.com 2019 - 2024. All rights reserved.