Set a reference to Microsoft Word. Then use the following code:
Public Sub OpenWordDoc(Path As String)
Dim WApp As Word.Application
Set WApp = CreateObject("Word.Application")
If Path <> "" Then
' Check if file exists, if not give error msg
If Dir(Path) = "" Then
Dim errormsg As String
errormsg = "The following document does not exist:"
errormsg = errormsg & vbCrLf
errormsg = errormsg & Path
errormsg = errormsg & vbCrLf & vbCrLf
errormsg = errormsg & "Cannot open this file."
MsgBox errormsg
Exit Sub
End If
WApp.Documents.Open Path, Visible:=True
Else
WApp.Documents.Add Visible:=True
End If
WApp.Visible = True
End Sub
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.