Problem with error trapping

M

McManCSU

I am writing a data compiling program that when run updates a master
sheet. I have files that have "_COMP" added to the end of the file
name if they have been updated. I am trying to open every file as if
it has the _COMP, but most do not, so an error is generated. I catch
the error no problem the first round, but on the next pass in a for
loop, it displays the error (from trying to open a file that doesnt
exist) rather than catching it. I have tried the error.clr call but
still no help. My code looks like this more or less:

For Each wsSheet In Worksheets
On Error GoTo notCOMP
Set wBook = Workbooks(wsSheet.name & "_COMP.xls")

If wBook Is Nothing Then 'Wkbk is NOT open
'Opens
Workbooks.Open Filename:="G:\ROHS\" & name & "\" &
wsSheet.name & "_COMP.xls"
On Error GoTo notCOMP
End If
........
<code>
........
notCOMP:
<code>
Err.Clear
Next wsSheet

Any ideas on why I cant clear out the error?
 
T

Tom Ogilvy

You need a resume statement in your error handler. Until a resume statement
is executed, you are still in error handler mode and an error in the error
handler causes excel to halt.

In the module, type
Resume
highlight it and hit F1. This will explain it to you.
 

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