Excel 2010 Bible

(National Geographic (Little) Kids) #1

Chapter 39: Introducing Visual Basic for Applications


821


As macros go, this example is okay, but it’s certainly not perfect. It’s not very flexible, and it
doesn’t include any error handling. For example, if the workbook structure is protected, trying to
add a new sheet will cause an error.


Learning More


This chapter barely scratches the surface of what you can do with VBA. If this is your first exposure
to VBA, you’re probably a bit overwhelmed by objects, properties, and methods. I don’t blame you.
If you try to access a property that an object doesn’t have, you get a run-time error, and your VBA
code grinds to a screeching halt until you correct the problem. Fortunately, several good ways are
available to learn about objects, properties, and methods.


l (^) Read the rest of the book. Subsequent chapters in this section contain additional infor-
mation and many more examples.
l (^) Record your actions. The best way to become familiar with VBA is to turn on the macro
recorder and record actions that you make in Excel. You can then examine the code to
gain some insights regarding the objects, properties, and methods.
l Use the Help system. The main source of detailed information about Excel’s objects,
methods, and procedures is the VBA Help system. Help is very thorough and easy to
access. When you’re in a VBA module, just move the cursor to a property or method and
press F1. You get help that describes the word that is under the cursor.
l Get another book. Several books are devoted exclusively to using VBA with Excel. My
book, Excel 2010 Power Programming with VBA (Wiley), is one.

Free download pdf