请教,用VBA在WORD中编了一个自定义的菜单,如何在关闭时自动删除
代码如下:
Private Sub Document_open()
'Sub test()
Set myM = CommandBars.ActiveMenuBar
Set MenuBars = myM.Controls.Add(Type:=msoControlPopup, Temporary:=True)
' Set MenuBars = myM.Controls.Add(Name:="mBar", Position:=msoBarRight, Temporary:=True)
MenuBars.Caption = "富电"
'MenuBars.Delete
'MenuBars("MyMenu").Menus.Add Caption:="富电"
Set ss = MenuBars.Controls.Add(Temporary:=True) '(Type:=msoControlButton)
With ss
.Caption = "搜索"
.OnAction = "Search"
End With
Set tj = MenuBars.Controls.Add(Temporary:=True) '(Type:=msoControlButton)
With tj
.Caption = "提交"
.OnAction = "Todatabase"
End With
Set dq = MenuBars.Controls.Add(Temporary:=True) '(Type:=msoControlButton)
With dq
.Caption = "读取"
.OnAction = "Readdatabase"
End With
Set sc = MenuBars.Controls.Add(Temporary:=True)
With sc
.Caption = "删除"
.OnAction = "Delete"
End With
Set tc = MenuBars.Controls.Add(Temporary:=True)
With tc
.Caption = "退出"
.OnAction = "Quit"
End With
运行是没有问题,可是每运行一次,也就是每打开一次都新建一个菜单加在后面,我已经定义了Temporary:=True
为什么关闭时临时菜单不会自动删除?
希望哪位大侠帮帮忙!
小弟不胜感激!
[解决办法]
Private Sub Document_Close() CommandBars.ActiveMenuBar.Controls("富电").DeleteEnd Sub