Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default Trap a checkbox click

Excel 2002, WinXP
An OP I am helping has dozens of Control Toolbox checkboxes on each of
several sheets. The idea is for a user to click on the individual checkbox
in response to a question.
The OP has a Private Sub CheckBoxX_Click() macro for each checkbox with some
12 lines of code to take specific actions if that specific checkbox is
clicked True or False. That seems to me to be an awkward way to execute
code for each checkbox.

Each checkbox is linked to a neighboring cell so that the user can see the
TRUE or FALSE in response to his click.. I thought I could pick up on that
Worksheet_Change as an event but I found that link doesn't trigger an event.

My question is this:
Is there a way to detect all of the following?
A checkbox has been clicked on.
Which checkbox has been clicked on?
What is the current state of that one checkbox?

Thanks for your help. Otto


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Trap a checkbox click

This technique works equally as well for checkboxes on worksheets as it does
for commandbuttons on userforms;

http://j-walk.com/ss/excel/tips/tip44.htm
John Walkenbach's site
Handle Multiple UserForm Buttons With One Subroutine

--
Regards,
Tom Ogilvy


"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
An OP I am helping has dozens of Control Toolbox checkboxes on each of
several sheets. The idea is for a user to click on the individual

checkbox
in response to a question.
The OP has a Private Sub CheckBoxX_Click() macro for each checkbox with

some
12 lines of code to take specific actions if that specific checkbox is
clicked True or False. That seems to me to be an awkward way to execute
code for each checkbox.

Each checkbox is linked to a neighboring cell so that the user can see the
TRUE or FALSE in response to his click.. I thought I could pick up on

that
Worksheet_Change as an event but I found that link doesn't trigger an

event.

My question is this:
Is there a way to detect all of the following?
A checkbox has been clicked on.
Which checkbox has been clicked on?
What is the current state of that one checkbox?

Thanks for your help. Otto




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default Trap a checkbox click

Thanks Tom. I'll look it up and see what I can do. Otto
"Tom Ogilvy" wrote in message
...
This technique works equally as well for checkboxes on worksheets as it
does
for commandbuttons on userforms;

http://j-walk.com/ss/excel/tips/tip44.htm
John Walkenbach's site
Handle Multiple UserForm Buttons With One Subroutine

--
Regards,
Tom Ogilvy


"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
An OP I am helping has dozens of Control Toolbox checkboxes on each of
several sheets. The idea is for a user to click on the individual

checkbox
in response to a question.
The OP has a Private Sub CheckBoxX_Click() macro for each checkbox with

some
12 lines of code to take specific actions if that specific checkbox is
clicked True or False. That seems to me to be an awkward way to execute
code for each checkbox.

Each checkbox is linked to a neighboring cell so that the user can see
the
TRUE or FALSE in response to his click.. I thought I could pick up on

that
Worksheet_Change as an event but I found that link doesn't trigger an

event.

My question is this:
Is there a way to detect all of the following?
A checkbox has been clicked on.
Which checkbox has been clicked on?
What is the current state of that one checkbox?

Thanks for your help. Otto






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default Trap a checkbox click

Tom
I need some more help with this. Using John's example for multiple
CommandButtons in a UserForm as you said, I have the following:
In a Class module I have:

Public WithEvents CheckBoxGroup As CheckBox

Private Sub CheckBoxGroup_Click()
MsgBox "Hello from " & CheckBoxGroup.Name
End Sub


In a regular module I have:
Option Explicit
Dim CheckBoxes() As New Class1

Sub SetupCBGroup() 'John's example was ShowDialog
Dim CheckBoxCount As Long
Dim ctl As Control
' Create the CheckBox objects
CheckBoxCount = 0
For Each ctl In ActiveSheet.Controls
If TypeName(ctl) = "CheckBox" Then
CheckBoxCount = CheckBoxCount + 1
ReDim Preserve CheckBoxes(1 To CheckBoxCount)
Set CheckBoxes(CheckBoxCount).CheckBoxGroup = ctl
End If
Next ctl
'John's example had a ShowUF here
End Sub

I understand that the above SetupCBGroup macro has to run in order to setup
the CheckBoxes array. I could use a Sheet_Activate event to run this macro.
But for now I tried to run that macro manually to setup the array and got
the following error on the first statement ("Public WithEvents CheckBoxGroup
As CheckBox)in the Class module:
Compile error:

Object does not source automation events


Tom, I'm on thin ice with this because all this is new to me. I appreciate
your help. Otto

"Tom Ogilvy" wrote in message
...
This technique works equally as well for checkboxes on worksheets as it
does
for commandbuttons on userforms;

http://j-walk.com/ss/excel/tips/tip44.htm
John Walkenbach's site
Handle Multiple UserForm Buttons With One Subroutine

--
Regards,
Tom Ogilvy


"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
An OP I am helping has dozens of Control Toolbox checkboxes on each of
several sheets. The idea is for a user to click on the individual

checkbox
in response to a question.
The OP has a Private Sub CheckBoxX_Click() macro for each checkbox with

some
12 lines of code to take specific actions if that specific checkbox is
clicked True or False. That seems to me to be an awkward way to execute
code for each checkbox.

Each checkbox is linked to a neighboring cell so that the user can see
the
TRUE or FALSE in response to his click.. I thought I could pick up on

that
Worksheet_Change as an event but I found that link doesn't trigger an

event.

My question is this:
Is there a way to detect all of the following?
A checkbox has been clicked on.
Which checkbox has been clicked on?
What is the current state of that one checkbox?

Thanks for your help. Otto






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Trap a checkbox click

Public WithEvents CheckBoxGroup As MSFORMS.CheckBox

There is a checkbox object in Excel that is not the MSforms (ActiveX)
checkbox - so you need to be specific.

--
Regards,
Tom Ogilvy


"Otto Moehrbach" wrote in message
...
Tom
I need some more help with this. Using John's example for multiple
CommandButtons in a UserForm as you said, I have the following:
In a Class module I have:

Public WithEvents CheckBoxGroup As CheckBox

Private Sub CheckBoxGroup_Click()
MsgBox "Hello from " & CheckBoxGroup.Name
End Sub


In a regular module I have:
Option Explicit
Dim CheckBoxes() As New Class1

Sub SetupCBGroup() 'John's example was ShowDialog
Dim CheckBoxCount As Long
Dim ctl As Control
' Create the CheckBox objects
CheckBoxCount = 0
For Each ctl In ActiveSheet.Controls
If TypeName(ctl) = "CheckBox" Then
CheckBoxCount = CheckBoxCount + 1
ReDim Preserve CheckBoxes(1 To CheckBoxCount)
Set CheckBoxes(CheckBoxCount).CheckBoxGroup = ctl
End If
Next ctl
'John's example had a ShowUF here
End Sub

I understand that the above SetupCBGroup macro has to run in order to

setup
the CheckBoxes array. I could use a Sheet_Activate event to run this

macro.
But for now I tried to run that macro manually to setup the array and got
the following error on the first statement ("Public WithEvents

CheckBoxGroup
As CheckBox)in the Class module:
Compile error:

Object does not source automation events


Tom, I'm on thin ice with this because all this is new to me. I

appreciate
your help. Otto

"Tom Ogilvy" wrote in message
...
This technique works equally as well for checkboxes on worksheets as it
does
for commandbuttons on userforms;

http://j-walk.com/ss/excel/tips/tip44.htm
John Walkenbach's site
Handle Multiple UserForm Buttons With One Subroutine

--
Regards,
Tom Ogilvy


"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
An OP I am helping has dozens of Control Toolbox checkboxes on each of
several sheets. The idea is for a user to click on the individual

checkbox
in response to a question.
The OP has a Private Sub CheckBoxX_Click() macro for each checkbox with

some
12 lines of code to take specific actions if that specific checkbox is
clicked True or False. That seems to me to be an awkward way to

execute
code for each checkbox.

Each checkbox is linked to a neighboring cell so that the user can see
the
TRUE or FALSE in response to his click.. I thought I could pick up on

that
Worksheet_Change as an event but I found that link doesn't trigger an

event.

My question is this:
Is there a way to detect all of the following?
A checkbox has been clicked on.
Which checkbox has been clicked on?
What is the current state of that one checkbox?

Thanks for your help. Otto










  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default Trap a checkbox click

Thanks Tom. I'll try it with that change. Otto
"Tom Ogilvy" wrote in message
...
Public WithEvents CheckBoxGroup As MSFORMS.CheckBox

There is a checkbox object in Excel that is not the MSforms (ActiveX)
checkbox - so you need to be specific.

--
Regards,
Tom Ogilvy


"Otto Moehrbach" wrote in message
...
Tom
I need some more help with this. Using John's example for multiple
CommandButtons in a UserForm as you said, I have the following:
In a Class module I have:

Public WithEvents CheckBoxGroup As CheckBox

Private Sub CheckBoxGroup_Click()
MsgBox "Hello from " & CheckBoxGroup.Name
End Sub


In a regular module I have:
Option Explicit
Dim CheckBoxes() As New Class1

Sub SetupCBGroup() 'John's example was ShowDialog
Dim CheckBoxCount As Long
Dim ctl As Control
' Create the CheckBox objects
CheckBoxCount = 0
For Each ctl In ActiveSheet.Controls
If TypeName(ctl) = "CheckBox" Then
CheckBoxCount = CheckBoxCount + 1
ReDim Preserve CheckBoxes(1 To CheckBoxCount)
Set CheckBoxes(CheckBoxCount).CheckBoxGroup = ctl
End If
Next ctl
'John's example had a ShowUF here
End Sub

I understand that the above SetupCBGroup macro has to run in order to

setup
the CheckBoxes array. I could use a Sheet_Activate event to run this

macro.
But for now I tried to run that macro manually to setup the array and got
the following error on the first statement ("Public WithEvents

CheckBoxGroup
As CheckBox)in the Class module:
Compile error:

Object does not source automation events


Tom, I'm on thin ice with this because all this is new to me. I

appreciate
your help. Otto

"Tom Ogilvy" wrote in message
...
This technique works equally as well for checkboxes on worksheets as it
does
for commandbuttons on userforms;

http://j-walk.com/ss/excel/tips/tip44.htm
John Walkenbach's site
Handle Multiple UserForm Buttons With One Subroutine

--
Regards,
Tom Ogilvy


"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
An OP I am helping has dozens of Control Toolbox checkboxes on each of
several sheets. The idea is for a user to click on the individual
checkbox
in response to a question.
The OP has a Private Sub CheckBoxX_Click() macro for each checkbox
with
some
12 lines of code to take specific actions if that specific checkbox is
clicked True or False. That seems to me to be an awkward way to

execute
code for each checkbox.

Each checkbox is linked to a neighboring cell so that the user can see
the
TRUE or FALSE in response to his click.. I thought I could pick up on
that
Worksheet_Change as an event but I found that link doesn't trigger an
event.

My question is this:
Is there a way to detect all of the following?
A checkbox has been clicked on.
Which checkbox has been clicked on?
What is the current state of that one checkbox?

Thanks for your help. Otto










  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default Trap a checkbox click

Tom
I got another error. It was "Object doesn't support this property or
method." and was in the "For Each ctl..." line in the following macro:
Sub SetupCBGroup()
Dim CheckBoxCount As Long
Dim ctl As Control
' Create the CheckBox objects
CheckBoxCount = 0
For Each ctl In ActiveSheet.Controls 'Error
If TypeName(ctl) = "CheckBox" Then
CheckBoxCount = CheckBoxCount + 1
ReDim Preserve CheckBoxes(1 To CheckBoxCount)
Set CheckBoxes(CheckBoxCount).CheckBoxGroup = ctl
End If
Next ctl
End Sub

Thanks for your help, Tom Otto
"Tom Ogilvy" wrote in message
...
Public WithEvents CheckBoxGroup As MSFORMS.CheckBox

There is a checkbox object in Excel that is not the MSforms (ActiveX)
checkbox - so you need to be specific.

--
Regards,
Tom Ogilvy


"Otto Moehrbach" wrote in message
...
Tom
I need some more help with this. Using John's example for multiple
CommandButtons in a UserForm as you said, I have the following:
In a Class module I have:

Public WithEvents CheckBoxGroup As CheckBox

Private Sub CheckBoxGroup_Click()
MsgBox "Hello from " & CheckBoxGroup.Name
End Sub


In a regular module I have:
Option Explicit
Dim CheckBoxes() As New Class1

Sub SetupCBGroup() 'John's example was ShowDialog
Dim CheckBoxCount As Long
Dim ctl As Control
' Create the CheckBox objects
CheckBoxCount = 0
For Each ctl In ActiveSheet.Controls
If TypeName(ctl) = "CheckBox" Then
CheckBoxCount = CheckBoxCount + 1
ReDim Preserve CheckBoxes(1 To CheckBoxCount)
Set CheckBoxes(CheckBoxCount).CheckBoxGroup = ctl
End If
Next ctl
'John's example had a ShowUF here
End Sub

I understand that the above SetupCBGroup macro has to run in order to

setup
the CheckBoxes array. I could use a Sheet_Activate event to run this

macro.
But for now I tried to run that macro manually to setup the array and got
the following error on the first statement ("Public WithEvents

CheckBoxGroup
As CheckBox)in the Class module:
Compile error:

Object does not source automation events


Tom, I'm on thin ice with this because all this is new to me. I

appreciate
your help. Otto

"Tom Ogilvy" wrote in message
...
This technique works equally as well for checkboxes on worksheets as it
does
for commandbuttons on userforms;

http://j-walk.com/ss/excel/tips/tip44.htm
John Walkenbach's site
Handle Multiple UserForm Buttons With One Subroutine

--
Regards,
Tom Ogilvy


"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
An OP I am helping has dozens of Control Toolbox checkboxes on each of
several sheets. The idea is for a user to click on the individual
checkbox
in response to a question.
The OP has a Private Sub CheckBoxX_Click() macro for each checkbox
with
some
12 lines of code to take specific actions if that specific checkbox is
clicked True or False. That seems to me to be an awkward way to

execute
code for each checkbox.

Each checkbox is linked to a neighboring cell so that the user can see
the
TRUE or FALSE in response to his click.. I thought I could pick up on
that
Worksheet_Change as an event but I found that link doesn't trigger an
event.

My question is this:
Is there a way to detect all of the following?
A checkbox has been clicked on.
Which checkbox has been clicked on?
What is the current state of that one checkbox?

Thanks for your help. Otto










Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to enable to click a checkbox? Eric Excel Discussion (Misc queries) 2 May 6th 09 03:54 PM
Click Checkbox Event Montana DOJ Help Desk Excel Programming 4 November 11th 04 04:25 AM
Using a macro to code a checkbox on click - Help Rog[_3_] Excel Programming 1 October 25th 04 07:16 PM
Assigning click event to OleObjects checkbox Jim McLeod Excel Programming 5 April 20th 04 07:02 PM
Trap Right CLick Insert Von Shean Excel Programming 1 January 22nd 04 04:42 AM


All times are GMT +1. The time now is 04:43 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"