none
How to get Word to pop up with a Macro Button in Excel? RRS feed

  • Question

  • I'd like to open a word document by pushing a Macro Button in Excel. I am able to open the document, but it doesn't pop up on the screen. I can see Word open on my task bar, but that is very discrete.  If someone else is using my worksheet, they might not notice that. I'd like it to fully pop up on the screen over the excel document that's open.  This is my current code:

    Sub SearchButton_Click() 'Search Button
        
        Dim objWord As Object
        Dim objDoc As Object
        
        Set objWord = CreateObject("Word.Application")
        Set objDoc = objWord.Documents.Open("S:FilePath")
        objWord.Visible = True
        
    End Sub
    Tuesday, September 5, 2017 8:22 PM

Answers

  • Hi,

    Add the following one line after "objWord.Visible = True":
    objWord.Activate

    This is my test code:
    Private Sub btn_OpenWordDoc_Click()
        Dim objWord As Object
        Dim objDoc As Object
        ' --
        Dim fileName As String
        fileName = "R:\00 北窓舎\01 PCサポート\00 MSDN_TechNet\00 Word\00 Word_2010_まる.docx"
        Set objWord = CreateObject("Word.Application")
        Set objDoc = objWord.Documents.Open(fileName)
        objWord.Visible = True
        objWord.Activate
    End Sub
    Regards,

    Ashidacchi

    • Marked as answer by afnellis Wednesday, September 6, 2017 12:25 PM
    Tuesday, September 5, 2017 10:36 PM

All replies

  • Hi,

    Add the following one line after "objWord.Visible = True":
    objWord.Activate

    This is my test code:
    Private Sub btn_OpenWordDoc_Click()
        Dim objWord As Object
        Dim objDoc As Object
        ' --
        Dim fileName As String
        fileName = "R:\00 北窓舎\01 PCサポート\00 MSDN_TechNet\00 Word\00 Word_2010_まる.docx"
        Set objWord = CreateObject("Word.Application")
        Set objDoc = objWord.Documents.Open(fileName)
        objWord.Visible = True
        objWord.Activate
    End Sub
    Regards,

    Ashidacchi

    • Marked as answer by afnellis Wednesday, September 6, 2017 12:25 PM
    Tuesday, September 5, 2017 10:36 PM
  • That worked initially, but now, as I keep using my program, it's back to just opening the word doc without bringing it to focus.  This time it flashes orange down in the taskbar though.

    Wednesday, September 6, 2017 12:51 PM