我创建了一个包含多个宏的Excel加载项。我在.xlam文件中的“ ThisWorkbook”中添加了以下代码。我可以通过开发人员标签上的“ Excel加载项”按钮激活加载项。当我关闭工作簿并备份它时,仍然可以通过“ Excel加载项”按钮激活该加载项,但是宏徽标不再出现在“加载项”选项卡上。知道为什么会这样吗?加载项未被禁用,并且位于受信任的文件位置。
用于在“加载项”标签上创建按钮的代码。
Private Sub Workbook_AddinInstall()
With Application.CommandBars("Standard").Controls.Add
.Caption = "Save New Version"
.FaceId = 3
.Style = msoButtonIconAndCaptionBelow
.OnAction = "Version_Save"
End With
With Application.CommandBars("Standard").Controls.Add
.Caption = "Create Delivery Workbook"
.FaceId = 263
.Style = msoButtonIconAndCaptionBelow
.OnAction = "DeliveryWorkbook"
End With
End Sub
当通过“ Excel加载项”按钮停用加载项时,用于从“加载项”选项卡中删除按钮的代码。
Private Sub Workbook_AddinUninstall()
On Error Resume Next
Application.CommandBars("Standard").Controls("Save New Version").Delete
Application.CommandBars("Standard").Controls("Create Delivery Workbook").Delete
End Sub