Error Handling - Show Message Box and then stop remaining code

gmooney

Active Member
Joined
Oct 21, 2004
Messages
252
Office Version
  1. 365
Platform
  1. Windows
Hi, I would like to throw a message box up if an error is encountered in the code that instructs the user to call or email me. Therefore I want to the code to stop after they click on OK for the message box.

How can I do this?
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Please post the code you are currently using.
 
Upvote 0
VBA Code:
'Place this near the top of the code before processing begins
On Error GoTo ErrHandler


'place this at the end of the code with no code after it
ErrHandler:
    MsgBox "Error Message please email me@gmail.com", vbOKOnly, "***ERROR***"
    On Error GoTo 0
 
Upvote 0
Thank you.....This gets me closer.

One thing I didn't mention that makes this slightly more challenging.

This code is in Excel.

Part of that code goes over to open up a PPT file and once that PPT file is open it starts to run code in the PPT.

Therefore that error actually happens in the PPT file.

Based on this error being captured in the PPT file I have used your code in the code area that is running when the PPT is doing it's thing. The problem now is that PPT is in the background while Excel is in forefront and the dialog box comes up behind Excel and the user doesn't know there was an error message. I tried to put an AppActivate statement back to the Excel file right before the MsgBox code above but that doesn't seem to work?
 
Upvote 0

Forum statistics

Threads
1,215,459
Messages
6,124,947
Members
449,198
Latest member
MhammadishaqKhan

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