Opening Word in Excel
In my situation, I have Word document names in a spreadsheet. All docs
listed are in the same folder as the workbook. This code gets the doc name
from the ActiveCell, and the doc file path from the workbook path. You will
need to adjust as required (you may want to use the BuiltIn FileOpen dialog
instead).
HTH
Ed
Sub FindDoc()
' ******
' NOTE: Use only _one_ of the bindings below.
' Comment out the other one. I have the early binding
' to help code, but use the late binding to run
' because I don't know the user's versions.
'Dim WD As New Word.Application
Dim WD As Object
' *******
Dim doc As String
Dim Fname As String
Dim Fpath As String
Err.Clear
' Get file path
Fpath = ThisWorkbook.Path
Sheets("Sheet1").Activate
' Get doc name from list page
Fname = ActiveCell.Text
' Open doc
doc = Fpath & "\" & Fname & ".doc"
On Error Resume Next
Set WD = GetObject(, "Word.Application")
If Err.Number < 0 Then
Set WD = CreateObject("Word.Application")
End If
Err.Clear
On Error GoTo 0
WD.Documents.Open doc
WD.Visible = True
WD.Quit
Set WD = Nothing
End Sub
"Jeralc" <u18775@uwe wrote in message news:5bf5e9a660038@uwe...
Hi. I'm trying to open a word document via a userform button so that I can
mailmerge from Excel. Anyone know how to do that?
|