Why doesn't "Resume Next" work?

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
 
N

Norman Jones

Hi Ed,

Do you have the 'Break on all errors' option checked?

Tools | Options | General Tab
 
I

impslayer

Ed skrev:
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

Hi Ed,

Are you sure the error emerges where you think, and not on the
"WD.Documents.Open doc" (which is out of the On Error Resume Next
scope)?

/impslayer
 
E

Ed

When the error occurs when the macro is run, the Debug / Exit alert box pops
up, the screen flips to the VBE, and the line highlighted in yellow is the
GetObject line. The WD.Documents.Open line works fine if an instance of
Word is already available. If not, I get the error.

Ed
 
E

Ed

As usual, Tom, that did it! I guess I had the mistaken assumption that On
Error Resume Next would override any setting to break on an error. I assume
this is an application setting, and not specific to an individual file or
template?

Ed
 
H

Helmut Weber

Hi Ed,

if you are using Word as editor for outlook
or even if only spellcheck in outlook is active,
kind of a _part_ of an instance of Word is active.
Have a look at processes in the windows task manager.
With this uncomplete word instance,
something on error trapping goes wrong.
First there is no error, and yet, an error occurs.

Which is no solution, I know.

There must be a way to check all running processes.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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