SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 248 | Next

Jim DeMarco

"Pro Excel 2007 VBA"


10. Press F5 until the code runs to completion.
Now that we??™ve seen how to debug and troubleshoot our code, let??™s take a look at how to
prevent errors from occurring and how to graciously notify users of errors.
Error Handling
Effective error handling is one of the major keys in providing a friendly experience to your
users. It??™s right up there with UI design in importance, and it can be the difference between a
dream and a nightmare from the user??™s perspective.
The Microsoft Office suite of tools is still VBA-based. Therefore we are still limited to the
On Error GoTo syntax for error handling. Be that as it may, we will look at some methods of
handling errors, and then we'll see how to deliver user-friendly messages to our users.
Is the File There?
One common error occurs when we try to open a file that is not available. In Chapter 3, we
opened files that contained various information ranging from CD lists to employee data. What
if the file wasn??™t there or was misnamed?
CHAPTER 7 n DEBUGGING AND ERROR HANDLING 275
In the Download section for this book on the Apress web site, find the file named
...XML_data.xlsm, and open the file. This is a blank workbook that includes code modules
from Chapter 3.
1. Open the VBE by clicking the Visual Basic command on the Code tab of the Developer
ribbon, or by pressing Alt+F11.
2. Open Standard Module1.
3. Find the GetXMLData subroutine. It is shown in Listing 7-7.
Listing 7-7. GetXMLData Procedure Before Modification
Sub GetXMLData()
ActiveWorkbook.


Pages:
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260