Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2009

    Unanswered: Set focus to word application in VBA?

    Hi. I'm currently using a word template with bookmarks that I control from access. When the user clicks a button, it opens the word template and replaces all the bookmarks, but then they have to manually switch to the word document to check it.

    Is there a way in VBA to keep the opened word document above access? Or maybe set focus to Word somehow?

    hjere's what I'm using
    Dim frmCurrentForm As Form
        Dim objWord As Word.Application
        Dim oBookmark
        'Find name of form that called function
        Set frmCurrentForm = Screen.ActiveForm
        'Start Microsoft Word.
        Set objWord = CreateObject("Word.Application")
        With objWord
            ' Make the application visible and open the document.
            .Visible = True
            .Documents.Open (file), , True
            ' Move to each bookmark and insert text from the form.
            For Each oBookmark In .ActiveDocument.Bookmarks
                .Selection.Text = frmCurrentForm.Controls(oBookmark)
        End With
        Set objWord = Nothing

  2. #2
    Join Date
    Mar 2003
    The Bottom of The Barrel
    Provided Answers: 1
    I'm not sure you can do that with Automation. Then again I'm not very familiar with trying to control windowing.

    The last time I did something like this I went straight to the windows API. This can be a little burly, but it's effective. Off the top of my head I think I had to rifle through FindWindowEx to get a proper window handle, and then pass that to GetWindow or SendKeys, depending on what I was doing. It's been a while though, hopefully that points you in the right direction.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Feb 2004
    Chicago, IL
    I believe it is the Activate method. Add this just after the With objWord line.


  4. #4
    Join Date
    Dec 2004
    Madison, WI
    I usually just open word using the shell command (ie. Call shell("MSWord.exe <parameters>")

    But I think your needs don't fit in with this type of opening.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

Posting Permissions

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