+ Reply to Thread
Results 1 to 6 of 6

regain focus on a userform

  1. #1
    Registered User
    Join Date
    09-19-2011
    Location
    oc,ca
    MS-Off Ver
    Excel 2003
    Posts
    44

    regain focus on a userform

    I have a userform and it occasionally loses focus because of other programs in the background. How do I pro grammatically regain focus?

    I have tried to use the focus method for sheet1 and workbook object but both failed to regain focus. Surprisingly the userform doesn't have a focus method.

  2. #2
    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: regain focus on a userform

    Hello david90,

    Is your user form a worksheet or a VBA UserForm?
    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!)

  3. #3
    Registered User
    Join Date
    09-19-2011
    Location
    oc,ca
    MS-Off Ver
    Excel 2003
    Posts
    44

    Re: regain focus on a userform

    it's a vba form.

  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: regain focus on a userform

    Hello david90,

    I am not really sure what you have done here. My guess is the UserForm Is displayed as non-modal. Otherwise, Excel would have to lose focus to another application before the UserForm would lose focus. The other puzzling piece is how is another application taking the focus if you have not switched to by clicking its window?

    A UserForm can be given the focus by it being displayed as non-modal and using the Windows API to set the focus to UserForm window. But this would have to be a macro run from the VBIDE and if the workbook does not have the focus then how can you run this macro?

  5. #5
    Registered User
    Join Date
    09-19-2011
    Location
    oc,ca
    MS-Off Ver
    Excel 2003
    Posts
    44

    Re: regain focus on a userform

    Hi,

    To clarify, my excel workbook has a userform that was created with the VBIDE. The userform's showmodal property is set to false to make it a non-modal window.

    On occasion, the userform would lose focus because I would click on other MS programs and forget to click on the userform again give it focus. My userform needs to have focus in order for it to work properly (the reason for this is not important in this discussion).

    I'm aware of the windows api that can be used to give my userform focus but are there any built in vba function that have the same function?

  6. #6
    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: regain focus on a userform

    Hello david90,

    Other than the user clicking the UserForm or one its controls, no there is not.

+ 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