RobDog888
Nov 7th, 2005, 12:00 AM
Menus and Toolbars are both actually the same objects so to speak. They both are part of the Office CommandBars collection. What specifies them as different between each other is the CommandBar Type.
A Menu Item is added to the "Menu Bar" CommandBar Item. Conversely, a ToolBar Button is added to the "Standard" CommandBar because the "Standard" CommandBar is the name of the default ToolBar.
Word 2003 Menu Item Example...
http://vbforums.com/attachment.php?attachmentid=48591
Word 2003 VBA Code Example:
Option Explicit
'<CREATE THE EVENT HANDLER>
Public WithEvents oCBBCustom As Office.CommandBarButton
'<EVENT PROCEDURE>
Private Sub oCBBCustom_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
MsgBox "Meow!"
End Sub
Private Sub Document_Open()
Dim oCB As Office.CommandBar
Dim oCBBTools As Office.CommandBarPopup
'<DRILL DOWN THE COMMANDBAR OBJECT HEIRARCHY>
Set oCB = Application.CommandBars("Menu Bar")
Set oCBBTools = oCB.Controls("&Tools")
'<ADD A NEW BUTTON>
Set oCBBCustom = oCBBTools.Controls.Add(msoControlButton, 1, , , True) 'Place our custom one at the bottom
With oCBBCustom 'position by leaving it empty or
.Caption = "VB/Office Guru SpellChecker™" 'specify a position. (0 based)
.BeginGroup = True
.Enabled = True
.Visible = True
End With
'<USE THE .RESET METHOD TO RESET THE COMMAND BAR TO ORIGINAL SETTINGS>
'oCB.Reset 'To reset the menu.
End Sub
A Menu Item is added to the "Menu Bar" CommandBar Item. Conversely, a ToolBar Button is added to the "Standard" CommandBar because the "Standard" CommandBar is the name of the default ToolBar.
Word 2003 Menu Item Example...
http://vbforums.com/attachment.php?attachmentid=48591
Word 2003 VBA Code Example:
Option Explicit
'<CREATE THE EVENT HANDLER>
Public WithEvents oCBBCustom As Office.CommandBarButton
'<EVENT PROCEDURE>
Private Sub oCBBCustom_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
MsgBox "Meow!"
End Sub
Private Sub Document_Open()
Dim oCB As Office.CommandBar
Dim oCBBTools As Office.CommandBarPopup
'<DRILL DOWN THE COMMANDBAR OBJECT HEIRARCHY>
Set oCB = Application.CommandBars("Menu Bar")
Set oCBBTools = oCB.Controls("&Tools")
'<ADD A NEW BUTTON>
Set oCBBCustom = oCBBTools.Controls.Add(msoControlButton, 1, , , True) 'Place our custom one at the bottom
With oCBBCustom 'position by leaving it empty or
.Caption = "VB/Office Guru SpellChecker™" 'specify a position. (0 based)
.BeginGroup = True
.Enabled = True
.Visible = True
End With
'<USE THE .RESET METHOD TO RESET THE COMMAND BAR TO ORIGINAL SETTINGS>
'oCB.Reset 'To reset the menu.
End Sub