Hi
Is there a way to create a macrobutton that enables me, when double-clicking
it, to toggle between two macros already created?
Russ - 17 Jun 2007 09:15 GMT
Are you talking about a toolbar button for a macro?
Toolbar buttons activate with one click.
Some options in Word can be toggled by code like:
Selection.Font.Bold = Not Selection.Font.Bold
If they are normally set with a value True or False.
Otherwise you have to find a way to store a value that can be tested each
time the button is activated.
Storing Values When a Macro Ends
http://snipurl.com/swu3
> Hi
> Is there a way to create a macrobutton that enables me, when double-clicking
> it, to toggle between two macros already created?

Signature
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID
yves@champollion.net - 17 Jun 2007 21:28 GMT
Rather than run yet another macro, would it not be simpler to toggle
the OnAction property of the button itself? After all, this is exactly
what is needed here, and Office VBA provides the resources. When any
of the two macros ends, have it toggle the button's OnAction property
by ending it with code like that:
If CommandBars("MyBar").Controls(ButtonIndex).OnAction="macro1" Then
CommandBars("MyBar").Controls(ButtonIndex).OnAction="macro2"
Else
CommandBars("MyBar").Controls(ButtonIndex).OnAction="macro1"
End If
where "MyBar" and ButtonIndex identify your button.
My two cents,
Yves Champollion
www.champollion.net
On Jun 17, 10:15 am, Russ <drsN0SPAMmi...@hotmailD0Tcom.INVALID>
wrote:
> Are you talking about a toolbar button for a macro?
> Toolbar buttons activate with one click.
[quoted text clipped - 19 lines]
>
> drsmN0SPAMikleAThotmailD0Tcom.INVALID
Russ - 17 Jun 2007 21:45 GMT
Very cool, Yves.
I haven't dealt with toolbar buttons that much, mainly I drag a routine into
a new menu to use it.
Thank goodness for the internet and forums to disseminate information.
> Rather than run yet another macro, would it not be simpler to toggle
> the OnAction property of the button itself? After all, this is exactly
[quoted text clipped - 34 lines]
>>> Is there a way to create a macrobutton that enables me, when double-clicking
>>> it, to toggle between two macros already created?

Signature
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID
Graham Mayor - 17 Jun 2007 09:27 GMT
You could run a third macro to toggle between them eg
Sub ChooseMacros()
Dim sMacro As String
Start:
sMacro = InputBox("Enter 'A' for Macro 1" & vbCr _
& "or 'B' for Macro2", "A")
If sMacro = "A" Or sMacro = "a" Then
Application.Run MacroName:="Macro1"
ElseIf sMacro = "B" Or sMacro = "b" Then
Application.Run MacroName:="Macro2"
Else: MsgBox "The choices are A or B!", vbCritical
GoTo Start:
End If
End Sub
Sub Macro1()
MsgBox "This is Macro1"
End Sub
Sub Macro2()
MsgBox "This is Macro2"
End Sub

Signature
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Hi
> Is there a way to create a macrobutton that enables me, when
> double-clicking it, to toggle between two macros already created?
Helmut Weber - 17 Jun 2007 12:27 GMT
Hi,
just another idea would be to check
ControlKeyState flags (API) and thus run
one out of of several macros,
depending on the ControlKeyState.
Like:
if left-shift then run Macro1
if right-shift then run Macro2
if Ctrl-shift-left then run macro3
Nothing for an end user
and for sure something for well organized people
or people with good memory.

Signature
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
Klaus Linke - 18 Jun 2007 15:59 GMT
> Hi
> Is there a way to create a macrobutton that enables me,
> when double-clicking it, to toggle between two macros already created?
Buttons also have a State property, that determines whether they look
"pressed" or "depressed".
You could have one macro that checks out the State, runs the appropriate
code, and toggles the button to the other State.
Sub TestState()
Dim myCBB As CommandBarButton
Set myCBB = CommandBars.ActionControl
Select Case myCBB.State
Case msoButtonDown
MsgBox "run code to lift the button"
myCBB.State = msoButtonUp
Case msoButtonUp
MsgBox "run code to press the button"
myCBB.State = msoButtonDown
Case msoButtonMixed
MsgBox "shouldn't happen"
myCBB.State = msoButtonDown
End Select
End Sub
Klaus
Klaus Linke - 18 Jun 2007 16:02 GMT
Sorry, misread the question completely!
Klaus
Bob W - 08 May 2008 15:54 GMT
Klaus,
How would you modify this macro to toggle the "backward paragraph" button
(ActiveWindow.ActivePane.View.ShowAll) on and off? I'm creating templates
for unsophisticated Word users; toggling this button lets them show/hide
hidden text instructions, but they don't know what the backward paragraph
button is, nor how to make it visible if it's not in their menu bar. Being
able to embed a macrobutton in the template that they could use to toggle it
on/off would be helpful.
> > Hi
> > Is there a way to create a macrobutton that enables me,
[quoted text clipped - 22 lines]
>
> Klaus