error handler

keithkemble

Board Regular
Joined
Feb 15, 2002
Messages
160
I have a routine that comprises several sub routines eg (in simple form):-

Sub cmrmenu()
On Error GoTo error
Application.ScreenUpdating = False
Dim SH As Worksheet
For Each SH In ThisWorkbook.Sheets
SH.Unprotect "password"

Application.ScreenUpdating = True
Sheets("menu").Select
Application.Run ("Cmr_Show_Please_Wait")
Application.ScreenUpdating = False

Application.Run "sortroutine.archive"
Application.Calculation = xlCalculationManual
Application.Run "cmrstarts1"
Application.Run "cmrterms1"
Application.Run "futurestarts1"
Application.Run "futureterms1"
Application.Run "cmrfutureststarts"
Application.Run "cmrfuturestterms"
Application.Run "price_reviews_started"
Application.Run "price_reviews_due"
Application.Run "nonhits"
Application.Run "extrahits"
Application.Run "cmr.localcallouts"
Sheets("menu").Select
Application.Run ("module1.Cmr_Hide_Please_Wait")
Application.ScreenUpdating = True

Application.Run "module1.protectall"
Sheets("menu").Select
Range("A1").Select

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Exit Sub

error:
Application.Run ("errorhandler")
End Sub

What I am trying to achieve is to run the errorhandler routine on ANY error within the overall routine. This error handler routine runs an automatuc calculation & protect the worksheets.

I cannot get it to work.

Should I put the
On Error code and error: label in EACH subroutine for it to work. ??
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
From Help:

An "enabled" error handler is one that is turned on by an On Error statement; an "active" error handler is an enabled handler that is in the process of handling an error. If an error occurs while an error handler is active (between the occurrence of the error and a Resume, Exit Sub, Exit Function, or Exit Property statement), the current procedure's error handler can't handle the error. Control returns to the calling procedure. If the calling procedure has an enabled error handler, it is activated to handle the error. If the calling procedure's error handler is also active, control passes back through previous calling procedures until an enabled, but inactive, error handler is found. If no inactive, enabled error handler is found, the error is fatal at the point at which it actually occurred. Each time the error handler passes control back to a calling procedure, that procedure becomes the current procedure. Once an error is handled by an error handler in any procedure, execution resumes in the current procedure at the point designated by the Resume statement.

Maybe you just need Resume or Resume Next immediately before End Sub.
 

David Huang

New Member
Joined
Jan 11, 2010
Messages
11
I'm pretty sure you can't trap errors across application.run. The error in caller below is caught, but the error in runner isn't.

Sub runner()
On Error Resume Next
Application.Run "called"
End Sub

Sub caller()
On Error Resume Next
Call called
End Sub

Sub called()
Debug.Print 1 / 0
End Sub

Also, when you put in a breakpoint and show the call stack, the application.run shows as cutting across non-basic code.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,096
Messages
5,768,058
Members
425,451
Latest member
JohnBrooksBiddle

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top