Dual Function Button Macros (Toogle ?)

  • Thread starter Thread starter robertguy
  • Start date Start date
R

robertguy

Hi,

can any please advise me on how to make a button dual function

i.e. when it is pressed once it performs one macro (and changes th
button text) and then when it is press again runs another macro an
changes the button text back to the original text

e.g.

<Button Text - “Format On”> runs a macro to format the spread shee
(in this case to remove tool bars etc) and then button text become
<Format Off>

<Burtton Text – “Format Off”> runs a macro to format the spread shee
(in this case to reinstall tool bars etc) and then button text become
<Format On>

Any help would be greatly appreciated


Ro
 
Hi
one way: Declare a static variable. e.g.

----
Private Sub CommandButton1_Click()
Static status As Boolean
If status Then
' your code for status = true
CommandButton1.Caption = "Status False"
status = False
Else
' your code for status = false
CommandButton1.Caption = "Status True"
status = True
End If

End Sub
 
Frank

I've built up the Private Sub CommandButton1_Click() as advised but ho
do I assign to the button as its not in the normal macro list


Ro
 
Hi
you first have to create the button if you want to use a commandbutton
:-)
Try the following
- Create a command button on your worksheet (e.g. use the toolbar
'Toolbox' to drag a button on your worksheet)
- Right click on this button and choose 'code'
- paste the code in the appearing VBA Editor (you may have to change
the name according to your commandbutton name)
- Close the VBA editor
 
Back
Top