View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Check box making a command button work

I used a button from the forms toolbar--is that what you meant?

You could either add some code to the button's code:

Option Explicit
Sub btnClick()

If ActiveSheet.CheckBoxes("Check box 1").Value = xlOff Then
MsgBox "nope, not today!"
Exit Sub
End If

'your real code here

MsgBox "it's working"

End Sub

Or you could disable the button (or hide it) when the checkbox changes:

Option Explicit
Sub CBXClick()
ActiveSheet.Buttons("button 1").Enabled _
= CBool(ActiveSheet.CheckBoxes("Check box 1").Value = xlOn)
'or hide it???
ActiveSheet.Buttons("button 1").Visible _
= CBool(ActiveSheet.CheckBoxes("Check box 1").Value = xlOn)
End Sub

If you really meant a commandbutton from the control toolbox toolbar, something
like:

Sub CBXClick()
ActiveSheet.CommandButton1.Enabled _
= CBool(ActiveSheet.CheckBoxes("Check box 1").Value = xlOn)
'or to hide it
ActiveSheet.CommandButton1.Visible _
= CBool(ActiveSheet.CheckBoxes("Check box 1").Value = xlOn)
End Sub

But the same kind of check inside the commandbutton's code would work ok (like
in btnclick procedure).


Rmagic wrote:

Hello

I have a check box on a sheet from the forms toolbar
I would like to make a command button work only when the check box is
ticked

Thank you

--
Rmagic
------------------------------------------------------------------------
Rmagic's Profile: http://www.excelforum.com/member.php...o&userid=28595
View this thread: http://www.excelforum.com/showthread...hreadid=484465


--

Dave Peterson