Err handler to stop execution

autigers

Board Regular
Joined
Oct 9, 2005
Messages
139
Hello ... getting close to testing with this thing ..
I have the code below which executes mutiple macros within ...
What I would like to have happen is that if there is an error after the Sheets("EETimecard").select occurs then I wish to have a message box and the code to stop ....

Code:
Sub RunDailyTotals()
On Error GoTo TheEnd

Application.ScreenUpdating = False
Application.Run ("InputChange")
Application.Run ("EETime")
MsgBox ("You are about about to update your shift end numbers.  ")



Sheets("EETimecard").Select
'Sheets("EETimecard").PrintOut Copies:=2, Collate:=True
MsgBox ("Please check the printer. The Employee Timcard is complete for  ") & Date

Application.Run ("Cal_DailyTotals")
Application.Run ("ExportHours")

MsgBox ("Daily Totals Completed. You must now fill in the Staffing & Daily Numbers ")
Application.Run ("Open_DailyProd")

TheEnd: Sheets("Log").Visible = xlSheetVisible

'add username date and time
    Sheets("Log").Range("B65536").End(xlUp).Offset(1, 0).Value = UserName
    Sheets("Log").Range("C65536").End(xlUp).Offset(1, 0).Value = NameOfComputer
    Sheets("Log").Range("D65536").End(xlUp).Offset(1, 0).Value = Date
    Sheets("Log").Range("D65536").End(xlUp).NumberFormat = "dd mmm yyyy"
    Sheets("Log").Range("E65536").End(xlUp).Offset(1, 0).Value = Time
    Sheets("Log").Range("G65536").End(xlUp).Offset(1, 0).Value = "User Err on End of shift"
    Sheets("Log").Range("H65536").End(xlUp).Offset(1, 0).Value = Err.Description
    Application.ScreenUpdating = True
    Sheets("DailyInput").Select
End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
I'm not sure about jumping between procedures, but a simple albeit not so clean answer would be to put the "On Error Goto " statment in each procedure that way when an error occurs each procedure would be set up to handle it in the fashion you desire. You would need a global variable to make sure that when you returned to the calling procedure, the code would stop.

In your controlling procedure declare the Public variable. In my example Flag is the global/public variable.


On Error goto GetOut


GetOut:
on error goto 0
Flag =1
msgbox.....
exit sub

after each call, insert an if statement to exit the sub if Flag=1

Application.Run ("Cal_DailyTotals")
if Flag = 1 then exit sub
Application.Run ("ExportHours")
If Flag = 1 then exit sub


Hope that's not too confusing. Helpful or no?
 
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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