自定义右键菜单Excel加载项未加载

时间:2018-11-19 10:34:52

标签: excel vba excel-vba excel-2010 excel-addins

我已经使用Ron de Bruin tutorial创建了自定义右键菜单。 在XLSM文件类型中使用它时,这没问题,但是当我尝试将其转换为Excel加载项时,不会出现右键单击菜单。我需要添加一些特定的代码来启用它吗?

我在“ ThisWorkbook”中使用的代码是:

Private Sub Workbook_Activate()
Call AddToCellMenu
End Sub

Private Sub Workbook_Deactivate()
Call DeleteFromCellMenu
End Sub

我在单独的模块中使用的代码是:

Sub AddToCellMenu()
Dim ContextMenu As CommandBar
Dim MySubMenu As CommandBarControl

Call DeleteFromCellMenu

Set ContextMenu = Application.CommandBars("Cell")

Set MySubMenu = ContextMenu.Controls.Add(Type:=msoControlPopup, before:=3)

With MySubMenu
    .Caption = "Recruitment"
    .Tag = "My_Cell_Control_Tag"

    With .Controls.Add(Type:=msoControlButton)
        .OnAction = "'" & ThisWorkbook.Name & "'!" & "Rejections"
        .FaceId = 97
        .Caption = "Format Rejections"
    End With
    With .Controls.Add(Type:=msoControlButton)
        .OnAction = "'" & ThisWorkbook.Name & "'!" & "Hires"
        .FaceId = 87
        .Caption = "Format Hires"
    End With

End With

ContextMenu.Controls(4).BeginGroup = True
End Sub



Sub DeleteFromCellMenu()
Dim ContextMenu As CommandBar
Dim ctrl As CommandBarControl

Set ContextMenu = Application.CommandBars("Cell")

For Each ctrl In ContextMenu.Controls
    If ctrl.Tag = "My_Cell_Control_Tag" Then
        ctrl.Delete
    End If
Next ctrl

On Error Resume Next
ContextMenu.FindControl(ID:=3).Delete
On Error GoTo 0
End Sub

拒绝和雇用是我要它调用的两个宏。这些是我知道可以正常工作的简单宏,因此不必理会为这些宏添加代码。

0 个答案:

没有答案
豫ICP备18024241号-1