Opening word file via VB Code

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

I am trying to open a word file when a user clicks on a
command button. So far, I have:

Dim oApp As Object

Set oApp = CreateObject("Word.Application")

oApp.Visible = True

This works, but it just opens up Word itself. How would I
make it so that a specific Word file is opened?
 
Mike,

Here is how I do it.

On Error Resume Next

Set objWord = GetObject(, "Word.Application")

If objWord Is Nothing Then

Set objWord = CreateObject("Word.Application")

End If

On Error GoTo INSERT NAME OF ERROR HANDLER HERE

objWord.Visible = True

Set objDoc = objWord.Documents.Open("PATH TO DOCUMENT")

Set objDoc = Nothing

Set objWord = Nothing
 
Back
Top