ABSTRACT

There are three categories of programming errors in general: compilation errors, runtime errors, and logic errors. Compilation errors are errors that prevent your program from running. When you run your Visual Basic for Applications (VBA) code, the Visual Basic compiler compiles the VBA code into binary language. Compilation errors are the easiest to handle, as they can be detected by the Visual Basic Editor. Logic errors are the hardest to find and fix. This chapter introduces some techniques for handling runtime errors and debugging tools for finding logic errors. It also introduces some best practices of VBA coding that can help minimize the number of errors. After studying the chapter, readers will be able to add error-handling code to VBA programs; use the debugging tools provided by VBA to debug VBA programs. Common methods for debugging VBA code include examining the code, inserting MsgBox statements, insert Debug.Print statements, and using VBA's built-in debugging tools.