none
Bring Word App to front? RRS feed

  • Question

  • Howdy all. Have a Access 2003 database that opens Word via VBA to print preview a document. Word opens in at the front in Office 2003 and 2007.

    But in Office 2010, the Word app stays in the background and does not come to forefront even if application activated, active window setfocus. It does now flash to get user's attention however the user may not pay attention and complain.

    Below is the print preview code.

    Thank you,

    Rey

        Public Sub Print_Preview()
            ' purpose: preview document and wait for user response to exit word instance
            '          call cls function to wait for user response
           
            If (Not (IsNull(m_wordFile)) Or m_wordFile = "") Then
                ' open doc as read-only
                'Stop
               
                ' set app window caption
                If (InStr(m_wordFile, "HCC") > 0) Then
                    m_objWord.Caption = "HCC Requirements"
                End If
               
                If (InStr(m_wordFile, "NPI") > 0) Then
                    m_objWord.Caption = "EV NPI Location"
                End If
               
                Set m_wordDoc = m_objWord.Documents.Open(m_wordFile, , True)
               
                ' make app visible
                m_objWord.Visible = True
                m_objWord.Application.Activate
               
                ' bring word document to front
                m_wordDoc.Activate
               
                ' class function IsDocumentedPrinted loops till user
                ' clicks Yes; used in calling form
                m_wordDoc.PrintPreview
               
                m_objWord.Application.WindowState = wdWindowStateMaximize
                m_objWord.Application.ActiveWindow.SetFocus
               
            End If
        End Sub

    Tuesday, February 28, 2012 7:49 PM

Answers

  • Prior to opening the word document you could execute this:

    Sub MinimizeAll()
        Dim shell As New shell
        shell.MinimizeAll
    End Sub


    Kind Regards, Rich ... http://greatcirclelearning.com

    • Marked as answer by Bruce Song Thursday, March 8, 2012 12:48 PM
    Tuesday, February 28, 2012 8:19 PM

All replies

  • Prior to opening the word document you could execute this:

    Sub MinimizeAll()
        Dim shell As New shell
        shell.MinimizeAll
    End Sub


    Kind Regards, Rich ... http://greatcirclelearning.com

    • Marked as answer by Bruce Song Thursday, March 8, 2012 12:48 PM
    Tuesday, February 28, 2012 8:19 PM
  • In Word 2007 VBA,

    shell 

    is flagged as not defined.

    -avraham

     
    Sunday, October 20, 2013 9:50 PM
  • You have to add the shell object as a reference. In the VBE go to Tools > References and add the Microsoft Shell Commands

    Kind Regards, Rich ... http://greatcirclelearning.com

    Sunday, October 20, 2013 10:08 PM