Private Sub Workbook_Open()
Call Addright '工作薄打开时调用添加右键菜单
End Sub
Sub Addright() '在模块中增加此过程
Dim Addpop As CommandBarPopup, Addbutton As CommandBarButton
On Error Resume Next '出现错误继续
Application.CommandBars('cell').Controls('自定义(&M)').Delete '删除右键上的自定义菜单,否则每一次打开都增加一次,当cell变为1,则为增加菜单(与文件并列的菜单)
Set Addpop = Application.CommandBars('cell').Controls.Add(Type:=msoControlPopup, before:=1) '增加一级菜单popup
Addpop.Caption = '自定义(&M)'
'菜单名称为自定义,当cell变为1,则为增加菜单下的按钮(与文件并列的菜单)
Set Addbutton = Addpop.Controls.Add(Type:=msoControlButton, before:=1) '增加二级菜单按钮'可以增加多个
With Addbutton
.Caption =
'插入作者' '菜单名称为插入作者
.FaceId =
30 '按钮图标
.OnAction =
'InsertAuthor' '按钮执行动作,调用InsertAuthor函数
End With
End Sub
Sub InsertAuthor() '在模块中增加此过
Call Addright '工作薄打开时调用添加右键菜单
End Sub
Sub Addright() '在模块中增加此过程
Dim Addpop As CommandBarPopup, Addbutton As CommandBarButton
On Error Resume Next '出现错误继续
Application.CommandBars('cell').Controls('自定义(&M)').Delete '删除右键上的自定义菜单,否则每一次打开都增加一次,当cell变为1,则为增加菜单(与文件并列的菜单)
Set Addpop = Application.CommandBars('cell').Controls.Add(Type:=msoControlPopup, before:=1) '增加一级菜单popup
Set Addbutton = Addpop.Controls.Add(Type:=msoControlButton, before:=1) '增加二级菜单按钮'可以增加多个
End Sub
Sub InsertAuthor() '在模块中增加此过
