Excel 2010 Bible

(National Geographic (Little) Kids) #1

Chapter 39: Introducing Visual Basic for Applications


811



  1. Draw the button on the worksheet. Excel displays the Assign Macro dialog box.

  2. In the Assign Macro dialog box, select the macro from the list.

  3. Click OK to close the Assign Macro dialog box.

  4. (Optional) Change the text that appears on the button to make it descriptive; right-
    click the button, choose Edit Text from the shortcut menu, and make your changes.


After performing these steps, clicking the button executes the assigned macro.

FIGURE 39.12

Adding a button to a worksheet so that it can be used to execute a macro.


Tip
You can also assign a macro to a button on your Quick Access toolbar. Right-click the Quick Access toolbar
and choose Customize Quick Access Toolbar from the shortcut menu. On the Quick Access Toolbar tab of the
Excel Options dialog box that appears, select Macros from the drop-down list on the left. Then select your
macro and click the Add button. To change the icon, click the Modify button. n


Writing VBA code

As demonstrated in the preceding sections, the easiest way to create a simple macro is to record
your actions. To develop more complex macros, however, you have to enter the VBA code manu-
ally — in other words, write a program. To save time, you can often combine recording with man-
ual code entry.

Before you can begin writing VBA code, you must have a good understanding of such topics as
objects, properties, and methods. And it doesn’t hurt to be familiar with common programming
constructs, such as looping and If-Then statements.

This section is an introduction to VBA programming, which is essential if you want to write (rather
than record) VBA macros. It isn’t intended to be a complete instructional guide. My book Excel
2010 Power Programming with VBA (Wiley) covers all aspects of VBA and advanced spreadsheet
application development.
Free download pdf