Results 1 to 3 of 3
  1. #1
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Moving focus off modeless UserForm (Word 2002 SP-2)

    Is there VBA that will open a modeless UserForm and immediately put the focus back on the main document window (while leaving the UserForm visible)?

    Google led me to a solution using 2 API calls (to SetFocus and GetActiveWindow), but is there a way that just uses VBA?

    APPENDIX: In case anyone who ever reads this post wants the API solution:

    Private Declare Function GetActiveWindow _
    Lib "USER32" () As Long
    Private Declare Function SetFocus _
    Lib "USER32" (ByVal hwnd As Long) As Long

    Dim lngHWnd As Long

    lngHWnd = GetActiveWindow

    'Code that shows the modeless UserForm goes here.

    Call SetFocus(lngHWnd)

  2. #2
    New Lounger
    Join Date
    Jul 2002
    Location
    Auckland, New Zealand
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Moving focus off modeless UserForm (Word 2002 SP-2)

    or just

    AppActivate ("Microsoft word")

  3. #3
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Moving focus off modeless UserForm (Word 2002 SP-2)

    AppActivate was just what I needed. Thank you. <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

    (In my case I had to change the line to AppActivate ActiveDocument.Name, since the editing window caption starts with the name of the document and AppActivate "Microsoft word" jumped me to the Help window instead.)

Posting Permissions

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