Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding the active control on a sheet

Status
Not open for further replies.

Stretchwickster

Programmer
Apr 30, 2001
1,746
GB
Does anyone know how to find the currently focused/active control on an Excel worksheet?

Clive [infinity]
Ex nihilo, nihil fit (Out of nothing, nothing comes)
 
A commandbutton (from the Visual Basic toolbar) or a text box (added from the Drawing toolbar not from the Visual Basic toolbar)

Clive [infinity]
Ex nihilo, nihil fit (Out of nothing, nothing comes)
 
Is this a continuation from your other thread ? ...thread707-605683

I know how to identify a textbox but not a commandbutton.
Here is how to find the active textbox .......

Sub find_active_textbox()
' this routine will only identify a textbox name if it is selected

If (TypeName(Selection) = "TextBox") Then
MsgBox "The textbox currently selected is called " & Application.Selection.Name
End If

End Sub


Hope this helps,
TopJack.
 
Did I mention .......

If you assign a macro to a textbox it no longer selects itself. Therefore my routine fails to identify. To find the choosen textbox use the "Application.Caller" variable to determine source of click as described in your other thread
(Thread707-605683).

I have to admit that I couldn't get a commandbutton to react properly to the "Application.Caller" variable. Maybe I'm doing something wrong.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top