Consulting

Results 1 to 3 of 3

Thread: Take Focus Away From UserForm After Initializing It

  1. #1
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    323
    Location

    Take Focus Away From UserForm After Initializing It

    Hello, I have a UF with a ComboBox on it. After its created (initialized) I want the focus to immediately go to a cell without clicking on it. So far the focus remains on the UF ComboBox until the UF change event is activated by using
    AppActivate ThisWorkbook.Windows(1).Caption
    It will also change focus if I click on a cell or use the up/down arrow keys. I've tried the following both in the UF initialize sub and the standard module where the sub that "shows" the UF is, with no success:

    Application.SendKeys ("{ESC}")
    AppActivate ("Microsoft Excel")          - Fails completely
    AppActivate ThisWorkbook.Windows(1).Caption
    AppActivate ActiveWorkbook.Windows(1).Caption
    AppActivate ThisWorkbook.Windows(1).Caption = True
    AppActivate ActiveWorkbook.Windows(1).Caption = True
    Range("B7").Activate
    I've attached a sample workbook for reference.
    Gary
    Attached Files Attached Files

  2. #2
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    The initialize event occurs when the form is loaded and before it is shown. I'd suggest you add a routine in a normal module that activates the workbook as per your first line of code, then call that from the Initialize event using Application.OnTime
    Be as you wish to seem

  3. #3
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    323
    Location
    Quote Originally Posted by Aflatoon View Post
    The initialize event occurs when the form is loaded and before it is shown. I'd suggest you add a routine in a normal module that activates the workbook as per your first line of code, then call that from the Initialize event using Application.OnTime
    Fantastic, Aflatoon your recommendation works great.

    Thx
    Gary

Tags for this Thread

Posting Permissions

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