+ Reply to Thread
Results 1 to 5 of 5

Userform .SetFocus on nothing

  1. #1
    Forum Contributor
    Join Date
    11-10-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    549

    Userform .SetFocus on nothing

    I have a userform with multiple buttons.
    I don't want to focus on any.
    Is there a way to do this.
    Or alternative focus on the Close (X) button using ".SetFocus".

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,720

    Re: Userform .SetFocus on nothing

    When a form is displayed, the default focus is on the first control in the form. You can set it to any control you want (it can even be a label) but it cannot be nothing. The X button is not part of the form, it's part of the Windows frame, so you cannot set focus using VBA built-in calls. It might be possible by calling the Windows API but I do not know how to do that.

    What else is on the form besides the buttons?

    If you give more background about what you are doing we might be able to suggest an alternative design that meets your underlying requirements.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Userform .SetFocus on nothing

    I don't think that you can set focus on a label, Jeff.

    Setting focus on a textbox with a zero width and height is one workaround.

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,720

    Re: Userform .SetFocus on nothing

    jason.b75, you are correct. Labels have the SetFocus method so I thought it would work, but it causes a runtime error.

  5. #5
    Forum Contributor
    Join Date
    11-10-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    549

    Re: Userform .SetFocus on nothing

    OK thanks for the input. I will just create another command button which is for Exit.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Setfocus on Userform
    By rabbit_post in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-29-2017, 04:09 PM
  2. [SOLVED] .setfocus on userform not working
    By janderson055 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 03-15-2017, 03:22 PM
  3. Userform setfocus does not work?
    By flabb in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-15-2016, 07:24 AM
  4. [SOLVED] SetFocus on a Userform TextBox
    By bibu in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-22-2015, 05:18 PM
  5. Excel UserForm SetFocus
    By gopal baheti in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-17-2015, 05:42 AM
  6. [SOLVED] SetFocus to another tab on a multi tab userform
    By abordeau in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-21-2014, 01:08 PM
  7. question setfocus on a userform
    By GregJG in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-27-2007, 11:28 AM

Tags for this Thread

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