+ 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
    338

    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
    Forum Moderator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    Pro 2019
    Posts
    14,571

    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.
    Making the world a better place one fret at a time | | |會 |會 |會 |會 | |:| | |會 |會
    Please read the rules
    If someone helped you, click on the star icon at the bottom of their post
    If your problem is solved, go to Thread Tools and select Mark This Thread Solved
    Don't attach a screenshot--just attach your Excel file! It's easier and will let us experiment with your data, formulas, and code.

  3. #3
    Forum Expert
    Join Date
    06-08-2012
    Location
    swindon, england
    MS-Off Ver
    Excel 2019 / Windows 10
    Posts
    4,876

    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
    Forum Moderator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    Pro 2019
    Posts
    14,571

    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
    338

    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)

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