Opening word file via VB Code

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?
 
D

Dave Jones

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
 

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.

Ask a Question

Top