Word macro, bringing data from Excel with find command, How do I .

A

Alex Ivanov

Try to add a line

on error goto errhandler

at the beginning of the macro code or near the statement that most likely
will cause the error.
Then at the end of the macro, just before End Sub type

Exit Sub
ErrHandler:
' your error handler code goes here, if you wish, like this one
msgbox err.number & " " & err.description
End Sub
 
S

silver

I am programming a macro in Word and searching for data in Excel to bring
into a Word table. Not all data is in the Excel spreadsheet. My macro
errors out when Excel doesn't find the seached-for text. How can I catch
this error?
 
S

silver

Alex,

Thank you. This does indeed catch the error ONCE. However, if I address
the error and return to the macro, it doesn't catch it upon subsequent
occurences. The sort of logic I'm really looking for is something like: IF
searching excel produces an error (or "data not found"), THEN put "missing"
in Word table ELSE bring over the data five rows down from the found data.
The ELSE and THEN parts work. It's finding something that will do the "IF".
There's some .find.found thing that I thought would go, but I'm new to
getting Word/Excel to interact in a macro and can't seem to make that go.
Also, there's ISERR type code in Excel VB, but that doesn't seem to work
either. Perhaps I'm not using these correctly? Additional assistance would
be most welcome!

Silver
 
A

Alex Ivanov

You may try to add "Resume Next" or "Resume YourLabel" at the end of the
error handler. See VBA Help for details.
It would be easier to give you a suggestion if you posted your macro.
 

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