Private Sub Workbook_Open()
' Function:自定义右键快捷菜单
Dim cmp As CommandBarPopup '定义一个弹出式控件
Application.CommandBars("Cell").Reset '单元格菜单重置
Set cmp = Application.CommandBars("Cell").Controls.Add(Type:=msoControlPopup, before:=1, temporary:=True)
' 添加单元格右键菜单,增加位置第一个
With cmp
.Caption = "自定义右键菜单" '菜单命名
' 下面添加子菜单
With .Controls.Add(Type:=msoControlButton, before:=1)
.Caption = "功能1" '子菜单名称
.FaceId = 39
.OnAction = "function1" 'function1是你自定义的功能名称
End With
With .Controls.Add(Type:=msoControlButton, before:=2)
.Caption = "功能2"
.FaceId = 39
.OnAction = "function2"
End With
End With
Set cmp = Nothing
End Sub