The Worksheet object is used frequently. Many times you'll use it as a gateway to the Range object on which your code needs to operate. Occasionally, you'll need to perform some worksheet-specific tasks such as protecting or unprotecting the worksheet or changing the worksheet's visibility.

The most important thing to keep in mind when you're working with Worksheet objects is that your end user can make changes that have the potential to break things. Worksheets can be renamed, moved, deleted, and otherwise modified. If you don't account for these possibilities, chances are you'll occasionally experience run-time errors. One simple thing you can do to prevent run-time errors is validate worksheet names before you use them in your code.

Finally, the events associated with the Worksheet object can be very useful. Because no events are associated with a Range object, you need to use Worksheet events to watch for events that occur that affect a range of interest. The SelectionChange event and Change event are both useful for this type of activity.

In the next chapter, I'll start the first of two chapters that covering the most important Excel object, the Range object. Not only is the Range object the most important object in terms of manipulating Excel programmatically, but it also has a great deal more properties and methods than any of the other objects we have looked at so far.

This page intentionally left blank

0 0

Post a comment