<

Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x

Basic Error Handling code for VBA and Microsoft Office

Posted on
24,665 Points
465 Views
2 Endorsements
Last Modified:
Experience Level: Intermediate
3:48
crystal (strive4peace) - Microsoft MVP, Access
Love empowering people by teaching and helping them develop applications.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code.

This lesson, Part 1, is the basics.  Whether you are writing VBA for Excel, Access, Word, or another Microsoft Office application,  basic error handling is the same.

Video Steps

01. Set up the error handler


   At the top of the code for your procedure, the error handler is set up using     On Error GoTo Proc_Err

02. Exit Code


   After whatever your procedure does, a line label for the exit code (such as Proc_Exit: ) is used to signify what happens at the end of the procedure. This can be code to cleanup object variables, or simply code to gracefully exit.

03. Error Handling Code


   After the exit code, a line label for the error handling code (such as Proc_Err: ) is used to begin what happens if there is an error.
Office 365 Training for IT Pros
Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

2
Comment
  • 2
3 Comments
 
LVL 22
This is a short video to introduce you to basic error handling code that can be used, not only in Excel, but in any VBA application.  While it is the first video in a 3-part series, it can be watched on its own.  Comfort with programming helps but is not necessary.

If you want to see how to apply this information to an Excel example, also watch:

Part 2. The next video in this 3-part series will cover the specific task that the code accomplishes, which is copying values to blank cells in a column of an Excel spreadsheet.  This step will show the manual process and the code to automate it.
http://www.experts-exchange.com/videos/1498/Excel-Error-Handling-Part-2-VBA-to-Copy-Values-Down-to-Blank-Cells-in-an-Excel-Column.html

Part 3. The last video in this series, part 3, breaks code that is working and shows how to use the error handler to fix errors and continue.
http://www.experts-exchange.com/videos/1518/Excel-Error-Handling-Part-3-Run-and-Fix-Bugs.html
0
 

Expert Comment

by:chris pike
For someone who is trying to wrap their brain around VB for the first time, this video is starting to shed light on the subject.
Well done video, very helpful.

Thanks so much.
I will definitely look out for more videos from crystal (strive4peace).
0
 
LVL 22
thank you, Chris and you're welcome  ~ if you have any questions about basic error handling, please post them here.
0

Featured Post

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Join & Write a Comment

Microsoft is moving in-place eDiscovery & hold from ECP to EOP console under Content Search in Search and Investigation Options.  In this post, I will be showing you how to export emails to a PST file using the Content Search Options.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Total Time: 17:40

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month