button focus

  • Thread starter Thread starter billq
  • Start date Start date
I don't know a way to do it in Excel VBA. But if you want a control to get the focus, you can use "SetFocus".

But even if there is a way to do it, I don't know how it can be applied. Maybe you can share with us why you need to do that.

----- billq wrote: -----

Hello, Need to know how to tell if a button has the focus.
thanks
bill
 
Set a flag in code when the button is clicked, reset the flag when
something else (another control, a worksheet cell, etc as appropriate)
is selected. Then, to know if the button has the focus, test the flag.
 
Hi and thanks for the reply. I have a combination of cells, command
buttons, and radio buttons that I am trying to set up a tab order using
Application.OnKey("{TAB}", "tabPress" to capture the tab key. For tabPress
I am using if then, elseif
structure to determine the active cell or button and where to move the
focus.
ex) if ActiveCell = Range("AccountNumber") then
Application.Goto Reference "Amount"
else if ActiveCell = Range("Amount") then
Sheet1.CashRB.Activate
else if Sheet1.CashRB 'this is where I need to determine if the
control has the focus so that I can move the focus to the next control

how this give you more idea as to what I am trying to do. If I had to do it
all over again I would make this sheet a form by itself.
thanks
bill
 
Something like:

Private m_blnHasFocusCashRB

If m_blnHasFocusCashRB Then

Application.Goto Reference "AccountNumber"
m_blnHasFocusCashRB = False

Else

If ActiveCell = Range("AccountNumber") then
Application.Goto Reference "Amount"
else if ActiveCell = Range("Amount") then
Sheet1.CashRB.Activate
m_blnHasFocusCashRB = True
End if

End if
 
Back
Top