L
lostwings
hi sue,
I have the following VBA code to add a "Custom Menu" to the main menu bar,
and add "Item 1" as a menu item to "Custom Menu". These two
CommandBarControls can be created correctly. But when I click the "Item 1",
it does not respond by poping out the "Hello" MsgBox.
For simplicity reason, I just omit the err event handler part to make the
snippet more clear to read. And I always assume that "Menu Bar" control is
always there before I launch this VBA code.
Thanks for any possible help.
Sub addmenu()
Dim objApp As Application
Dim colCB As CommandBars
Dim objCB As CommandBar
Dim objMenuControl As CommandBarControl
Dim objItemControl As CommandBarControl
Set objApp = CreateObject("Outlook.Application")
Set colCB = objApp.ActiveWindow.CommandBars
Set objCB = colCB("Menu Bar")
Set objMenuControl = objCB.Controls.Add(msoControlPopup)
objMenuControl.Caption = "Custom Menu"
objMenuControl.Enabled = True
objMenuControl.Visible = True
Set objItemControl = objMenuControl.Controls.Add(1)
objItemControl.Caption = "Item 1"
objItemControl.Enabled = True
objItemControl.OnAction = "myForm"
objItemControl.Visible = True
Set objApp = Nothing
Set colCB = Nothing
Set objCB = Nothing
Set objMenuControl = Nothing
End Sub
Sub myForm()
MsgBox ("hello")
End Sub
I have the following VBA code to add a "Custom Menu" to the main menu bar,
and add "Item 1" as a menu item to "Custom Menu". These two
CommandBarControls can be created correctly. But when I click the "Item 1",
it does not respond by poping out the "Hello" MsgBox.
For simplicity reason, I just omit the err event handler part to make the
snippet more clear to read. And I always assume that "Menu Bar" control is
always there before I launch this VBA code.
Thanks for any possible help.
Sub addmenu()
Dim objApp As Application
Dim colCB As CommandBars
Dim objCB As CommandBar
Dim objMenuControl As CommandBarControl
Dim objItemControl As CommandBarControl
Set objApp = CreateObject("Outlook.Application")
Set colCB = objApp.ActiveWindow.CommandBars
Set objCB = colCB("Menu Bar")
Set objMenuControl = objCB.Controls.Add(msoControlPopup)
objMenuControl.Caption = "Custom Menu"
objMenuControl.Enabled = True
objMenuControl.Visible = True
Set objItemControl = objMenuControl.Controls.Add(1)
objItemControl.Caption = "Item 1"
objItemControl.Enabled = True
objItemControl.OnAction = "myForm"
objItemControl.Visible = True
Set objApp = Nothing
Set colCB = Nothing
Set objCB = Nothing
Set objMenuControl = Nothing
End Sub
Sub myForm()
MsgBox ("hello")
End Sub