Excel右键菜单看不到自定义函数

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

各位专家早上好。

我的团队创建了 Excel 插件工具栏,以便最终用户更轻松地打开我们的 Excel 宏工具。我最近注意到这些加载项代码中的自定义函数不再在 Excel“右键单击”菜单上显示(或可访问)。我们使用 Windows 10 / 64 位 MS Office 365/2016。我想知道是否有人知道这些 UDF 是否被 Microsoft 禁用。我无法知道我们公司的安全措施是否禁用了这些功能。我已包含以下上下文代码:

Public Sub AddItemToCellMenu()
'Application.CommandBars("Cell").Reset
Dim cmdBar As CommandBar, cmdPopup As CommandBarPopup, cmdButton As CommandBarButton

On Error GoTo ErrorHandler:

Set cmdBar = Application.CommandBars("Cell") '35
Set cmdPopup = cmdBar.Controls.Add(Type:=msoControlPopup, Before:=1)

With cmdPopup
   .Caption = "My Popup"
End With

Set cmdButton = cmdPopup.Controls.Add(Type:=msoControlButton)
With cmdButton
   .Caption = "This is my macro1"
   .OnAction = "Mymacro1"
   .FaceId = 370
End With

Set cmdButton = cmdPopup.Controls.Add(Type:=msoControlButton, Before:=1)
With cmdButton
   .Caption = "This is my macro2"
   .OnAction = "Mymacro2"
   .FaceId = 370
End With

Exit Sub

ErrorHandler:

Debug.Print Err.Number & " " & Err.Description

End Sub
Public Sub Mymacro1()
MsgBox "My macro 1"
End Sub
Public Sub Mymacro2()
MsgBox "My macro 2"
End Sub

提前感谢您,VBA_Guy

我尝试执行上面的代码没有成功。我希望有更多关于这种现象的在线文档。

excel vba user-defined-functions add-in right-click
1个回答
0
投票
  • 您的代码更改了

    Normal
    Page Layout
    的内容菜单。但它不会改变
    Page Break Preview
    上的菜单。

  • 两个内容菜单名称都是

    Cell

请尝试一下。

Public Sub AddItemToCellMenu()
    Dim cmdBar As CommandBar, cmdPopup As CommandBarPopup, cmdButton As CommandBarButton
    On Error GoTo ErrorHandler:
    For Each cmdBar In Application.CommandBars
        If cmdBar.Name = "Cell" Then
            cmdBar.Reset
            Set cmdPopup = cmdBar.Controls.Add(Type:=msoControlPopup, Before:=1)
            With cmdPopup
                .Caption = "My Popup"
            End With
            Set cmdButton = cmdPopup.Controls.Add(Type:=msoControlButton)
            With cmdButton
                .Caption = "This is my macro1"
                .OnAction = "Mymacro1"
                .FaceId = 370
            End With
            Set cmdButton = cmdPopup.Controls.Add(Type:=msoControlButton, Before:=1)
            With cmdButton
                .Caption = "This is my macro2"
                .OnAction = "Mymacro2"
                .FaceId = 370
            End With
        End If
    Next
    Exit Sub
ErrorHandler:
    Debug.Print Err.Number & " " & Err.Description
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.