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
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