How to open a Word document using VBA
hbe
-
f894009 Posted messages 17417 Registration date Status Member Last intervention -
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
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
-
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