ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Focus (https://www.excelbanter.com/excel-programming/305976-focus.html)

Roy Miller[_3_]

Focus
 
I suspect this is possible to do in VBA but I am at a loose end on ho
it is done.

On a userForm that has multiple objects in multiple frames, is i
possible to find out which object at any particular time, irrespectiv
of which frame it is in, has currently got the focus ?

Any ideas?

Thanks in advance

R

--
Message posted from http://www.ExcelForum.com


Harald Staff

Focus
 
Hi RM

In theory (this demo click the form surface outside controls to run):

Private Sub UserForm_Click()
MsgBox Me.ActiveControl.Name
End Sub

Problems arise when you use containers, frames and multipages, which I
understand youn will. They will be the active control and you have to dig
for THEIR active control. The approach would be like this

Private Sub UserForm_Click()
On Error Resume Next
MsgBox Me.ActiveControl.Name
MsgBox Me.Controls(Me.ActiveControl.Name).ActiveControl.N ame
End Sub

now you decide how many levels deep are needed and which errors to trap if
there are fewer levels when you search. Problem is probably not that big
when you know what this is for and when it's gonna run.

HTH. Best wishes Harald


"Roy Miller " skrev i melding
...
I suspect this is possible to do in VBA but I am at a loose end on how
it is done.

On a userForm that has multiple objects in multiple frames, is it
possible to find out which object at any particular time, irrespective
of which frame it is in, has currently got the focus ?

Any ideas?

Thanks in advance

R M


---
Message posted from http://www.ExcelForum.com/




Roy Miller[_4_]

Focus
 
This looks about right, I will try it out when I get back off holiday.

Roy


---
Message posted from http://www.ExcelForum.com/



All times are GMT +1. The time now is 01:04 PM.

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