How to open a Word document using VBA

hbe -  
f894009 Posted messages 17417 Registration date   Status Member Last intervention   -
Hello,

I would like to know how to open a Word document from a macro in an Excel document.
Thank you for your help.

Configuration: Windows XP / Firefox 11.0

2 answers

  1. narcocamaro1 Posted messages 7 Registration date   Status Member Last intervention   4
     
    You can use Word objects by referencing Word in Tools/References.

    Then, simply instantiate a Word session in Access:

    Sub Word()
    Dim strFile As String
    Dim objWord As New Word.Application

    strFile = "C:\Documents\MyFile.doc"

    ' open a Word document
    objWord.Documents.Open strFile
    ' make Word visible
    objWord.Visible = True

    ' your code

    ' close the document
    objWord.Documents(1).Close
    ' quit the Word application
    objWord.Quit

    ' free up memory
    Set objWord = Nothing
    End Sub
    5
    1. hbe
       
      Thank you for your prompt response. I would like to clarify my question: I would like to open a Word document via Excel VBA. So, I need to initiate the opening in the Excel macro. How can I do this, please?
      Thanks for your help.
      0
    2. f894009 Posted messages 17417 Registration date   Status Member Last intervention   1 717
       
      Re,
      What do you want to do with this Word document? (simple consultation, data copying, ...)
      0