PC Review


Reply
Thread Tools Rate Thread

Determine check status of worksheet checkbox?

 
 
robotman
Guest
Posts: n/a
 
      31st May 2007
I have a checkbox on a worksheet but can't figure out how to tell in
VBA whether it's checked or not.

I reference the check box with:

Sheets("Mysheet").Shapes("MyCheckBox")

Can someone tell me the syntax to determine the check status?

Thanks.

John

 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      31st May 2007
Checkbox from the Forms toolbar:

if worksheets("mySheet").checkboxes("myCheckbox").value = xlon then
'it's checked

Checkbox from the Control toolbox toolbar:

If Worksheets("mysheet").mycheckbox.Value = True Then
'it's checked

robotman wrote:
>
> I have a checkbox on a worksheet but can't figure out how to tell in
> VBA whether it's checked or not.
>
> I reference the check box with:
>
> Sheets("Mysheet").Shapes("MyCheckBox")
>
> Can someone tell me the syntax to determine the check status?
>
> Thanks.
>
> John


--

Dave Peterson
 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      31st May 2007
> VBA whether it's checked or not.
>
> I reference the check box with:
>
> Sheets("Mysheet").Shapes("MyCheckBox")
>
> Can someone tell me the syntax to determine the check status?


I'm newly returned to Excel, so I'm not up-to-date on everything about it,
so I'm not sure of you Shapes reference; but when I put a CheckBox on a work
sheet, I do it from the Visual Basic ToolBox and draw it directly onto the
sheet. I can then reference it directly within VBA using its name... and the
property you want is the Value property. Use

MyCheckBox.Value

for code on the Worksheet itself. If you are referencing across Worksheets,
then use

Sheets("Mysheet").MyCheckBox.Value

The Value property will be either True (if checked) or False (if not
checked).

Rick

 
Reply With Quote
 
robotman
Guest
Posts: n/a
 
      31st May 2007
Thanks! xlOn works....but who at Microsoft developed that?!! Now I
don't feel so bad for not figuring that out. And xlOff = -4146?

My macro will be cross-platform and objects from the VB Toolbox don't
function correctly on a Mac (at least not drop down boxes). I'm not
sure why, but I'm forced to use the Forms toolbox on the worksheet.

** Is there any way to capture events with the Forms checkbox (like
when the checkbox is checked/unchecked)? **

Thanks!

John

 
Reply With Quote
 
robotman
Guest
Posts: n/a
 
      31st May 2007
I meant objects from the *Control* tool box don't work on the Mac.

Rick, I'm also not able to create a check box from the VB Toolbox.
When I click off a form in VB, the toolbox disappears.

Thanks.

John


 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      31st May 2007
You could assign it a macro (rightclick on it an assign macro).

Option Explicit
Sub testme()

Dim myCBX As CheckBox
Set myCBX = ActiveSheet.CheckBoxes(Application.Caller)

If myCBX.Value = xlOn Then
MsgBox "It's checked"
Else
MsgBox "It's not checked"
End If

End Sub

This goes in a general module.

By using this line:
Set myCBX = ActiveSheet.CheckBoxes(Application.Caller)
You can assign the same macro to all the checkboxes -- and still know which one
was clicked (Application.caller will return its name).

robotman wrote:
>
> Thanks! xlOn works....but who at Microsoft developed that?!! Now I
> don't feel so bad for not figuring that out. And xlOff = -4146?
>
> My macro will be cross-platform and objects from the VB Toolbox don't
> function correctly on a Mac (at least not drop down boxes). I'm not
> sure why, but I'm forced to use the Forms toolbox on the worksheet.
>
> ** Is there any way to capture events with the Forms checkbox (like
> when the checkbox is checked/unchecked)? **
>
> Thanks!
>
> John


--

Dave Peterson
 
Reply With Quote
 
robotman
Guest
Posts: n/a
 
      31st May 2007
Thanks! xlOn works....but who at Microsoft developed that?!! Now I
don't feel so bad for not figuring that out. And xlOff = -4146?

My macro will be cross-platform and objects from the VB Toolbox don't
function correctly on a Mac (at least not drop down boxes). I'm not
sure why, but I'm forced to use the Forms toolbox on the worksheet.

** Is there a way to disable (gray out) checkboxes created from the
Forms toolbox? **


> so I'm not sure of you Shapes reference; but when I put a CheckBox on a work
> sheet, I do it from the Visual Basic ToolBox and draw it directly onto the


When I click off a VB form, the VB ToolBox goes away. Are you talking
about another toolbox like the Controls or Forms from the worksheet
level or am I missing something?

Thanks!

John

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      1st Jun 2007
You can disable those checkboxes with something like:

ActiveSheet.CheckBoxes("check box 1").Enabled = False

But they won't grey out. You may want to hide them???

ActiveSheet.CheckBoxes("check box 1").Visible = False

robotman wrote:
>
> Thanks! xlOn works....but who at Microsoft developed that?!! Now I
> don't feel so bad for not figuring that out. And xlOff = -4146?
>
> My macro will be cross-platform and objects from the VB Toolbox don't
> function correctly on a Mac (at least not drop down boxes). I'm not
> sure why, but I'm forced to use the Forms toolbox on the worksheet.
>
> ** Is there a way to disable (gray out) checkboxes created from the
> Forms toolbox? **
>
> > so I'm not sure of you Shapes reference; but when I put a CheckBox on a work
> > sheet, I do it from the Visual Basic ToolBox and draw it directly onto the

>
> When I click off a VB form, the VB ToolBox goes away. Are you talking
> about another toolbox like the Controls or Forms from the worksheet
> level or am I missing something?
>
> Thanks!
>
> John


--

Dave Peterson
 
Reply With Quote
 
robotman
Guest
Posts: n/a
 
      1st Jun 2007
(last post was something old... google burped!)

Dave... thanks for the macro suggestion. I like the generic
"Application.Caller".

John


 
Reply With Quote
 
robotman
Guest
Posts: n/a
 
      1st Jun 2007
I meant objects from the *Control* tool box don't work on the Mac.

Rick, I'm also not able to create a check box from the VB Toolbox.
When I click off a form in VB, the toolbox disappears.

Thanks.

John


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Coordinate status of checkbox on form to checkbox on multiple reco DanRoy Microsoft Access 0 4th Sep 2008 09:18 PM
Re: Determine check status of worksheet checkbox? robotman Microsoft Excel Programming 0 1st Jun 2007 03:03 AM
determine CheckBox's checkedChange status dynamically? =?Utf-8?B?ZGF2aWQ=?= Microsoft ASP .NET 4 4th May 2005 03:10 PM
Syntax to check protected status of a worksheet? slingsh0t@hotmail.com Microsoft Excel Misc 2 18th Jan 2005 02:53 PM
Can't check ActiveX checkbox on worksheet onedaywhen Microsoft Excel Programming 3 9th Aug 2003 02:34 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:45 PM.