E
Ed
I wrote a macro in Excel 2000 VBA to open a document in Word 2000. I used
code from the GetObject Help file to check if Word is already active. But
the code stops on an error generated by using GetObject - "Active X
component can't create object." On Error Resume Next does not drop the code
through to the next line.
Can someone explain what I have wrong?
Ed
Sub FindDoc()
Dim WD As Object
Dim doc As String
Dim Fname As String
Dim Fpath As String
' Get file path
Fpath = ThisWorkbook.Path
Sheets("Sheet1").Activate
' Get doc number from list page
Fname = ActiveCell.Text
' Open doc
On Error Resume Next
' **ERROR NEXT LINE**
Set WD = GetObject(, "Word.Application")
MsgBox Err.Number
If Err.Number <> 0 Then
Set WD = CreateObject("Word.Application")
End If
Err.Clear
On Error GoTo 0
doc = Fpath & "\" & Fname & ".doc"
WD.Documents.Open doc
WD.Visible = True
End Sub
code from the GetObject Help file to check if Word is already active. But
the code stops on an error generated by using GetObject - "Active X
component can't create object." On Error Resume Next does not drop the code
through to the next line.
Can someone explain what I have wrong?
Ed
Sub FindDoc()
Dim WD As Object
Dim doc As String
Dim Fname As String
Dim Fpath As String
' Get file path
Fpath = ThisWorkbook.Path
Sheets("Sheet1").Activate
' Get doc number from list page
Fname = ActiveCell.Text
' Open doc
On Error Resume Next
' **ERROR NEXT LINE**
Set WD = GetObject(, "Word.Application")
MsgBox Err.Number
If Err.Number <> 0 Then
Set WD = CreateObject("Word.Application")
End If
Err.Clear
On Error GoTo 0
doc = Fpath & "\" & Fname & ".doc"
WD.Documents.Open doc
WD.Visible = True
End Sub