Results 1 to 8 of 8
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Activedoc vs modeless userform (WinXP/Word2003)

    I have some code that opens a modeless userform to act like a toolbar, just leaving it there ready to be used. However, I need the focus to be returned to the Word windows itself, or more explicitly the first available formfield (it's protected).

    Can anyone tell me the line of code I need to return focus to the document, please?

    Many thanks
    Beryl M


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Activedoc vs modeless userform (WinXP/Word2003)

    Why not use a toolbar then? You can have text boxes and combo boxes on a toolbar.

    You can put a label on your userform instructing the user to click in the document...

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Activedoc vs modeless userform (WinXP/Word2003)

    Thanks for the reply, Hans, but - does that mean there isn't a bit of code I can use to return the focus to the document window?
    Beryl M


  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Activedoc vs modeless userform (WinXP/Word2003)

    Not that I know of. A Google search turned up this, but it doesn't work for me. You could try it to see if it works for you, though.

  5. #5
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Activedoc vs modeless userform (WinXP/Word2003)

    Anything's worth a try, although this looks bit complicated for such a simple request...! I'll let you know how I get on!
    Beryl M


  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Activedoc vs modeless userform (WinXP/Word2003)

    The following version does work for me:

    At the beginning of a standard module:

    Public Declare Function GetActiveWindow Lib "user32" () As Long
    Public Declare Function SetActiveWindow Lib "user32" (ByVal hwnd As Long) As Long

    Code to open the userform:

    Sub OpenForm()
    Dim lngHwnd As Long
    lngHwnd = GetActiveWindow()
    UserForm1.Show vbModeless
    SetActiveWindow lngHwnd
    ActiveDocument.Bookmarks("Text1").Range.Fields(1). Result.Select
    End Sub

    Replace UserForm1 with the name of your userform, and Text1 with the name of the bookmark corresponding to the first form field in your document.

  7. #7
    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: Activedoc vs modeless userform (WinXP/Word2003)

    In Word 2002, I've successfully used this line:

    AppActivate ActiveDocument.Name

    UPDATE: I'm reminded I learned this technique right here at the Lounge, in <!post=this thread,408194>this thread<!/post>.

  8. #8
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Activedoc vs modeless userform (WinXP/Word2003)

    Yep, that worked!
    Beryl M


Posting Permissions

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