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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
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.
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,303
Members
449,078
Latest member
nonnakkong

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
Back
Top