18.11.2014 Views

Microsoft Office

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Part VI<br />

Programming Excel with VBA<br />

What You Can Do with VBA<br />

VBA is an extremely rich programming language with thousands of uses. The following list contains just a<br />

few things that you can do with VBA macros. (Not all of these tasks are covered in this book.)<br />

n Insert boilerplate text: If you need to enter standard text into a range of cells, you can create a<br />

macro to do the typing for you.<br />

n Automate a procedure that you perform frequently: For example, you may need to prepare a<br />

month-end summary. If the task is straightforward, you can develop a macro to do it for you.<br />

n Automate repetitive operations: If you need to perform the same action in 12 different workbooks,<br />

you can record a macro while you perform the task once — and then let the macro repeat your<br />

action in the other workbooks.<br />

n Create a custom command: For example, you can combine several of Excel’s commands so that<br />

they’re executed from a single keystroke or from a single mouse click.<br />

n Create a simplified “front end” for users who don’t know much about Excel: For example, you<br />

can set up a foolproof data-entry template.<br />

n Develop a new worksheet function: Although Excel includes a wide assortment of built-in functions,<br />

you can create custom functions that greatly simplify your formulas.<br />

n Create complete macro-driven applications: Excel macros can display custom dialog boxes and<br />

respond to new commands added to the Ribbon.<br />

n Create custom add-ins for Excel: Most add-ins shipped with Excel were created with Excel<br />

macros. I used VBA exclusively to create my Power Utility Pak.<br />

Figure 39.1 shows how the Ribbon looks when the Developer tab is selected.<br />

FIGURE 39.1<br />

The Developer tab, which does not appear by default, contains useful commands for VBA users.<br />

About Macro Security<br />

Macro security was a key priority in developing Excel 2007. The reason is that macros are powerful — so<br />

powerful that they can do serious damage to your computer. The macro security features in Excel 2007<br />

were created to help prevent macro-related problems.<br />

Figure 39.2 shows the Macro Settings section of the Trust Center dialog box. To display this dialog box,<br />

choose Developer ➪ Macro Security.<br />

682

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!