ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Need to know what is selected (https://www.excelbanter.com/excel-programming/355651-need-know-what-selected.html)

Maria J-son[_2_]

Need to know what is selected
 
Hi,
To a routine, I need to know what is selected on worksheet_change and
worksheet_selectionchange. I need It to take different actions depending on
the type... Selections could be like

Cells
Buttons
CheckBoxes
TextBox
Worksheets
ChartObjects

Most important right now is to find if it is a button selected (in the
shapes collection i think, not OLE). The other types in the list will soon
come to, however.

Can somebody please share a good routine for this?

/Regards



Nicholas B

Need to know what is selected
 
Maria

As far as I can see the WorkSheet Selection Change only works with changes
to cells, it doesn't seem to fire as you chose different buttons.
To get around this I suggest you use the GotFocus Event of each object
(TextBox, CommandButton, etc)
Write something into the GotFocus Method that fires a common checking routine
Eg
Private Sub CommandButton1_GotFocus()
Run "MyGeneralCheckingRoutine", "CommandButton1"
End Sub

Your Checking Routine is then being told which Object has been selected and
you can act on that

Hope this helps

Nick
"Maria J-son" wrote:

Hi,
To a routine, I need to know what is selected on worksheet_change and
worksheet_selectionchange. I need It to take different actions depending on
the type... Selections could be like

Cells
Buttons
CheckBoxes
TextBox
Worksheets
ChartObjects

Most important right now is to find if it is a button selected (in the
shapes collection i think, not OLE). The other types in the list will soon
come to, however.

Can somebody please share a good routine for this?

/Regards




Maria J-son[_2_]

Checking routine more important right now
 
Hi and thanks,

I'll look more into how to trig it. Now, more important is the actual
checking routine - how to find out what is selected.

/Regards

"Nicholas B" skrev i meddelandet
...
Maria

As far as I can see the WorkSheet Selection Change only works with changes
to cells, it doesn't seem to fire as you chose different buttons.
To get around this I suggest you use the GotFocus Event of each object
(TextBox, CommandButton, etc)
Write something into the GotFocus Method that fires a common checking
routine
Eg
Private Sub CommandButton1_GotFocus()
Run "MyGeneralCheckingRoutine", "CommandButton1"
End Sub

Your Checking Routine is then being told which Object has been selected
and
you can act on that

Hope this helps

Nick
"Maria J-son" wrote:

Hi,
To a routine, I need to know what is selected on worksheet_change and
worksheet_selectionchange. I need It to take different actions depending
on
the type... Selections could be like

Cells
Buttons
CheckBoxes
TextBox
Worksheets
ChartObjects

Most important right now is to find if it is a button selected (in the
shapes collection i think, not OLE). The other types in the list will
soon
come to, however.

Can somebody please share a good routine for this?

/Regards






Bob Phillips[_6_]

Need to know what is selected
 
Objects do not trigger the SelectionChange event, they have their own click
events if OLE objects, or assigned macros if shapes or forms controls, so
you will need to handle them all separately.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Maria J-son" wrote in message
...
Hi,
To a routine, I need to know what is selected on worksheet_change and
worksheet_selectionchange. I need It to take different actions depending

on
the type... Selections could be like

Cells
Buttons
CheckBoxes
TextBox
Worksheets
ChartObjects

Most important right now is to find if it is a button selected (in the
shapes collection i think, not OLE). The other types in the list will soon
come to, however.

Can somebody please share a good routine for this?

/Regards





Nicholas B

Checking routine more important right now
 
Maria

The GotFocus Event is automatically triggered when you select the button by
clicking on it. So, before the Click event fires, the GotFocus should fire.

The "how to find out what is selected." is done by telling your routine what
is selected. Every Object will have its own GotFocus Code - Not just one
for the whole sheet - so each one tells the General Routine which button it
is"
Eg CommandButton1_GorFocus()
Run "MyGeneralCheckingRoutine", "CommandButton1"
Eg CommandButton2_GorFocus()
Run "MyGeneralCheckingRoutine", "CommandButton2"
Eg TextBox1_GorFocus()
Run "MyGeneralCheckingRoutine", "TextBox1"
Eg CommandButton3_GorFocus()
Run "MyGeneralCheckingRoutine", "CommandButton3"

Nick
"Maria J-son" wrote:

Hi and thanks,

I'll look more into how to trig it. Now, more important is the actual
checking routine - how to find out what is selected.

/Regards

"Nicholas B" skrev i meddelandet
...
Maria

As far as I can see the WorkSheet Selection Change only works with changes
to cells, it doesn't seem to fire as you chose different buttons.
To get around this I suggest you use the GotFocus Event of each object
(TextBox, CommandButton, etc)
Write something into the GotFocus Method that fires a common checking
routine
Eg
Private Sub CommandButton1_GotFocus()
Run "MyGeneralCheckingRoutine", "CommandButton1"
End Sub

Your Checking Routine is then being told which Object has been selected
and
you can act on that

Hope this helps

Nick
"Maria J-son" wrote:

Hi,
To a routine, I need to know what is selected on worksheet_change and
worksheet_selectionchange. I need It to take different actions depending
on
the type... Selections could be like

Cells
Buttons
CheckBoxes
TextBox
Worksheets
ChartObjects

Most important right now is to find if it is a button selected (in the
shapes collection i think, not OLE). The other types in the list will
soon
come to, however.

Can somebody please share a good routine for this?

/Regards








All times are GMT +1. The time now is 06:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com