Programming in Microsoft Excel

Introduction to Event Procedures ■ Enabling and Disabling Events ■ Event Sequences ■ Worksheet Events

■ Workbook Events ■ Chart Events ■ Embedded Chart Events ■ Events Recognized by the Application Object

How do you disable a built-in shortcut menu when a user clicks on a worksheet cell? How do you display a custom message before a workbook is opened or closed? How can you validate data entered in a cell or range of cells? To get complete control over Microsoft Excel, you must learn how to respond to events. Learning how to program events will allow you to implement your own functionality in an Excel application. The first thing you need to learn about this subject matter is what an event is. Here's a simple definition:

An event is something that happens.

Needless to say, events happen to objects that are part of Microsoft Excel. However, once you learn about events in Excel, you will find it easier to understand events that occur to objects in Word or any other Microsoft Office application. Events are actions recognized by an object.

Now that you know what events are, you need to know that events can be triggered by an application user (such as yourself), another program, or the system itself. So, how can you trigger an event? Suppose you right-click a worksheet cell. This particular action would display a built-in shortcut menu for a worksheet cell, allowing you to quickly access the most frequently used commands related to worksheet cells. But what if this particular built-in response isn't appropriate under certain conditions? You may want to entirely disallow right-clicking in a worksheet or perhaps ensure that a custom menu appears on a cell shortcut menu when the user right-clicks any cell. The good news is you can use VBA to write code that can react to events as they occur.

Microsoft Excel provides many events to which you can respond. The following objects can respond to events:

■ Application

You can decide what should happen when a particular event occurs by writing an event procedure.

0 0

Post a comment