Chapter 16. Excel Macros and Visual Basic

If you find yourself doing the same thing over and over, that’s the perfect moment to ask yourself, “Shouldn’t my Mac be doing this work?” Invariably, the answer is yes. That’s particularly true if you’re using an Office program that has built-in macros supported by Visual Basic for Applications (VBA). This chapter shows you how to record and run macros and introduces some of the basic concepts behind Visual Basic.

Turn on the Macro recorder, and it watches your actions, keeping track of the cells you change, and the menu or ribbon commands you use. After you stop the recorder, those details are stored in a macro. Whenever you want to do the same thing, you can play back that recorded macro.

Visual Basic for Applications is a scripting language. Think of it as the junior version of a full-blown programming language. VBA was designed from the ground up to work with Office programs. When you combine its programming power with the features already built into features of Excel, Word, and PowerPoint, you can tackle a whole slew of projects. Programming pros design sophisticated custom programs using VBA and Office applications. You could write three books this size and not cover everything there is to know about Visual Basic for Applications, so this chapter is simply a dip-your-toe-in-the-water introduction.

One of the greatest things about macros and Visual Basic is their relationship. When you record a macro, your actions are transcribed into ...

Get Office 2011 for Macintosh: The Missing Manual now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.