First, you have to establish a reference to the Word 11.0 Object library from
the Visual Basic Editor (Tools/References). Assuming the button on the
worksheet is named btn_Run and the Word document is named Test.doc, the
following code will open the Word document in the same location as the
worksheet.
Private Sub btn_Run_Click()
Dim WordDoc As Word.document
Dim path As String
'The "path" variable is the location of the workbook
path = Application.Workbooks("TestWKB.xls").path
'Open Word document
Set WordDoc = Word.documents.Open(path & "\test.doc")
'Close Word document
WordDoc.Close
End Sub
"Sarah (OGI)" wrote:
> I have a worksheet in excel.
> I also have a word document (saved in the same directory), which has links
> with the details on this worksheet.
> I have added a command button with the intention that the user will be able
> to click on the button and invoke the word document.
> What code do I need to use in order to do this, or is there another way
> around this?
> Any help appreciated. Thanks in advance.
|