Adding a menu on built-in menu bar when opening document.

J

JuneTheSecond

I am going to add a menu item on built in menu bar when i open the document.
But the menu dissapears as soon as it appears. when I am going to add using
Office CommandBar object. Would anyone advice me what is wrong? Any comments
or advice would be appreciated. Of couse, there is no problem when I use
UIObject. But I wish to know the reason why it dissapears when i use Office
Command Bar object. There was no problem in Excel, when I tried the same
code on opening the work sheet. The code I am trying is as follows.
Thank you for your comments in advance.

[ThisDocument]
Sub document_documentopened(ByVal doc As IVDocument)
AddMenu1
End Sub

[Module1]
Sub AddMenu1()
Dim myMenuBar As Office.CommandBar
Dim newMenu As Office.CommandBarControl
Dim ctrl1 As Office.CommandBarControl

Set myMenuBar = Application.CommandBars.ActiveMenuBar
Set newMenu = myMenuBar.Controls.Add(Type:=msoControlPopup,
Temporary:=True)
newMenu.Caption = "Menu1"
Set ctrl1 = newMenu.Controls.Add(Type:=msoControlButton, ID:=1)
ctrl1.Caption = "TEST"
ctrl1.OnAction = "test"
ctrl1.TooltipText = "Menu Made by me"
ctrl1.Style = msoButtonCaption
End Sub

Sub test()
MsgBox "TEST"
End Sub
 
J

JuneTheSecond

And, the new menu appears normally, when I add new menu to the standard tool
bar. This is examined just replacing a line,
Set myMenuBar = Application.CommandBars.ActiveMenuBar
into
Set myMenuBar = Application.CommandBars("Standard")
I wonder why I cannot add new menu to the menu bar.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top