Macro

  • Thread starter Thread starter pbdefool
  • Start date Start date
P

pbdefool

How do you create a macro in excel that will open a
specific MS Word File?
 
One way:

Option Explicit
Sub CommandButton1_Click()

Dim oWord As Object
Dim myWordDocument As String
Dim testStr As String

myWordDocument = "C:\DATA\Word\mydocument.doc"

testStr = ""
On Error Resume Next
testStr = Dir(myWordDocument)
On Error GoTo 0
If testStr = "" Then
MsgBox myWordDocument & " doesn't exist"
Exit Sub
End If

On Error Resume Next
Set oWord = GetObject(, "Word.Application")
If Err Then
Set oWord = CreateObject("Word.Application")
End If

oWord.Visible = True
oWord.Documents.Open myWordDocument
AppActivate "Microsoft Word"

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.

Ask a Question

Back
Top