您的代码更改了
Normal
和Page Layout
Page Break Preview
的菜单。
Cell
。
在M365上进行了测试
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