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

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Moving focus off modeless UserForm (Word 2002 SP-2)

    Author
    Topic
    #409928

    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)

    Viewing 1 reply thread
    Author
    Replies
    • #877799

      or just

      AppActivate (“Microsoft word”)

      • #877999

        AppActivate was just what I needed. Thank you. cheers

        (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.)

      • #878000

        AppActivate was just what I needed. Thank you. cheers

        (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.)

    • #877800

      or just

      AppActivate (“Microsoft word”)

    Viewing 1 reply thread
    Reply To: Moving focus off modeless UserForm (Word 2002 SP-2)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: