>I know how to create a custom toolbar with menu items that invoke macros.
>The
[quoted text clipped - 13 lines]
> Thanks,
> Peter
>You can't pass a parameter but you can tell which menu item invoked the
>macro by querying ...
>
> CommandBars.ActionControl
>
> ... which seems like it will fit the bill
As a concrete example, run the first of these macros to create a
custom command bar with two buttons, both of which invoke the same
second macro. The second macro displays the .Tag of the clicked
button; you could use it, for example, to save the document with a
different name or to a different path. Or you could use the .Tag
string to simulate an enumerated type, and use the value in a Switch
Case statement to control the action.
Each button also has a .Parameter property that can serve as a second
"argument" if needed.
Sub SetupCB()
' run me once
Dim myCB As CommandBar
Dim myButn1 As CommandBarControl, myButn2 As CommandBarControl
Application.CustomizationContext = ActiveDocument
Set myCB = CommandBars.Add(Name:="CustomA",
Position:=msoBarFloating)
Set myButn1 = myCB.Controls.Add(Type:=msoControlButton)
Set myButn2 = myCB.Controls.Add(Type:=msoControlButton)
myCB.Enabled = True
myCB.Visible = True
With myButn1
.Style = msoButtonCaption
.Caption = "1"
.Tag = "first.doc"
.OnAction = "DifferentActions"
End With
With myButn2
.Style = msoButtonCaption
.Caption = "2"
.Tag = "second.doc"
.OnAction = "DifferentActions"
End With
End Sub
Sub DifferentActions()
' called by the buttons on the custom bar
MsgBox CommandBars.ActionControl.Tag
End Sub
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
Peter - 19 Dec 2007 12:56 GMT
Thank you, that was very helpful. It turns out that my select statement uses
an enumerated type and all I had to do was to set that in the .Tag field and
it worked.
Peter
> >You can't pass a parameter but you can tell which menu item invoked the
> >macro by querying ...
[quoted text clipped - 50 lines]
> Microsoft Word MVP FAQ: http://word.mvps.org
> Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.