View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default Set Error handling INSIDE error-trap

You should be able to change the way errors are handling inside an error
haqndler. If is very normal to use On Error GoTo 0 inside an error handler
to return error handling to a normal mode.

"Michelle" wrote:

Thats an even better reply than the last one - thanks - but do you knowe if
I can change the way errors are handled in the error trap anyway - for
future reference.

M


"Tim Williams" <timjwilliams at gmail dot com wrote in message
...
If after closing your datafile (in the "normal" flow) you 'Set DataFile =
Nothing' then you can test for that in the error handler

ie.

If Not DataFile Is Nothing then
DataFile.Close SaveChanges:=False
End If



"Michelle" wrote in message
...
I am having a problem with my error trap.

I want to have my error-trap simplydisplay a message and close the
data-file that's being used. However, if the error is generated 'late-on'
in my macro, the data-file may already be closed, so to handle this, I am
usingthe following code:

'===========================
Exit Sub

ErrorTrap:
MsgBox "The Macro has encountered an unforeseen problem" & vbCr & "and
cannot continue", vbCritical, "Error " & Err
Application.Calculation = xlCalculationAutomatic

Err.Clear
On Error Resume Next ' in case the sheets are already protected or
data file is already closed

' and close the data file
DataFile.Close SaveChanges:=False
'===========================

but the 'On Error Resume Next ' line seems to be ignored because it
generates a standard VB error (with the Debug-box displayed). Is this
because I am in an error trap? is there a way around this?

thanks

M