+ Reply to Thread
Results 1 to 10 of 10

Who's got focus

  1. #1
    Registered User
    Join Date
    07-09-2010
    Location
    Helsingborg, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    26

    Who's got focus

    Is it possible to find out which control in the Userform that has Focus?

  2. #2
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Who's got focus

    Please Login or Register  to view this content.
    If your question has been satisfactorily addressed, please consider marking it solved. Click the Thread Tools dropdown and select Mark thread as solved.
    Also, you might want to add to the user's reputation by clicking the star icon in the lower left corner of the post with the answer- it's why we do what we do...

    Thomas Lafferty
    Analyst/Programmer

  3. #3
    Registered User
    Join Date
    07-09-2010
    Location
    Helsingborg, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    26

    Re: Who's got focus

    Sorry, sorry!
    I forgot to tell that the controls are on a Multipage and then the only reply by "Me.ActiveControl.Name" will be MultiPage1

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Who's got focus

    Hello Mats Samson,

    Add this function in the Declarations section of the UserForm. You can then call it from anywhere in your code. It returns the control with the focus.

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Who's got focus

    try:
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    07-09-2010
    Location
    Helsingborg, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    26

    Re: Who's got focus

    Hello!
    Leith: I can't get your function to work, (even when exchanging x with SelCtrl)
    Thomas: You're getting closer! As the controls are "grouped" in Frames, the reply is Frame415,
    eg. the Frame where f.i. the TextBox is located.

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Who's got focus

    Hello Mats Samson,

    Did you copy the code to the top of your UserForm?

    Did you call it like below? Remember, the function it is returning the control itself.
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    07-09-2010
    Location
    Helsingborg, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    26

    Re: Who's got focus

    Hello Leith,
    thanks, it works OK!
    I used MsgBox GetActiveControl (), not .....Name
    Cheers
    Mats

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Who's got focus

    Hell Mats,

    I am happy it something easy to fix. Thanks for letting me know what you did.

  10. #10
    Registered User
    Join Date
    07-09-2010
    Location
    Helsingborg, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    26

    Re: Who's got focus

    Quote Originally Posted by Leith Ross View Post
    Hell Mats,

    I am happy it something easy to fix. Thanks for letting me know what you did.
    Leith,
    is it possible to include named range(s) connected to the controls (text- & comboboxes) and take action in the connected cell depending on which control is in focus? The RowSource connection is made via the code, not in the control itself. (There are also a variable connected to each control, but as I understand variables cannot be referenced via concatenation)
    Regards
    Mats

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1