Recording Macros

Project stores macros in the Visual Basic for Applications (VBA) programming language. And, if you're adept at programming, you can write your macro directly in the VBA programming language. Figure 24-1 shows a sample of the instructions that are stored in a macro in Visual Basic.

Figure 24-1: A sample set of instructions that are stored in a macro.

Most people prefer to record a macro. When you record a macro, you have Project memorize the steps that you want to take and then store those steps. That is, you do whatever it is you want Project to do. Project then converts those actions into Visual Basic statements and stores the statements in a macro. Later, when you want to take that action again, you run your macro, which I discuss in the next section.

Before you record a macro, you should run through the steps that you want to take. You may even want to write down the steps. That way, you are less likely to make (and record) mistakes.

Suppose that you find yourself often displaying a split view with the Gantt Chart on top and the Task Details Form below. Since you do this often, it would make a useful macro. First, walk through the process to create the view, so that you know what steps you take:

1. Open the View menu, and click Gantt Chart.

Tip By selecting the view first, you force Project to start your macro from the Gantt

% Chart view, regardless of the view that you were using before you ran your macro.

2. Choose WindowOSplit to open the bottom pane that shows, by default, the Task Form view.

3. Click the bottom pane, and choose ViewOMore Views to open the More Views dialog box.

4. Select the Task Details Form.

5. Click Apply.

Now that you know what you're going to record, use the following steps to record the macro:

1. Choose ToolsOMacroORecord New Macro to open the Record Macro dialog box, as shown in Figure 24-2.

Figure 24-2: The Record Macro dialog box.

2. Enter a name for the macro in the Macro name box.

Tip The first character of the macro name must be a letter, but the other characters can be letters, numbers, or underscore characters. You can't include a space in a * macro name, so try using an underscore character as a word separator, or capitalize the first letter of each word.

3. (Optional) To assign the macro to a keyboard shortcut, type a letter in the Shortcut key box. The letter that you assign can be any letter key on your keyboard, but it can't be a number or a special character. You also can't assign a key combination that is already used by Microsoft Project. If you select a reserved letter, Project displays the warning message that is shown in Figure 24-3 when you click OK.


^Note jlNote

Figure 24-3: Project displays this warning message if you select a keyboard shortcut that's already in use.

Keyboard shortcuts are only one of the ways that you can run a macro. In the section "Using Shortcuts to Run Macros," later in this chapter, you discover other methods to play back a macro as well as how to assign a keyboard shortcut after you've recorded and stored your macro.

4. In the Record Macro dialog box, open the Store macro in list box and click the location where you want to store the macro. You can store the macro in the Global File or in the current project. To make a macro available to all projects, select Global File.

The Global File is also called the Global template file, and it acts like the Normal template in Word or the Bookl template in Excel. Any customized features (such as macros, toolbars, or menus) that you store in the Global File are available to any project file. On the other hand, customized features that you store in an individual project file are available only to that file.

5. Type a description of the macro or the function that it performs in the Description box. This description appears whenever you run the macro from the Macros dialog box.

6. Use the options that are in the Row references and Column references sections to control the way that the macro selects rows and columns if you select cells while running a macro. For rows, the macro always selects rows — regardless of the position of the active cell — because it records relative references to rows. If you want a macro to always select the same row, regardless of which cell is first selected, select Absolute (ID).

For columns, the macro always selects the same column each time that it is run — regardless of which cell is selected first—because the macro records absolute references to columns. If you want a macro to select columns, regardless of the position of the active cell when you run the macro, select Relative in the Column references section.

7. Click OK, and Project redisplays your project. You don't notice any differences, but Project is now recording each action that you take.

8. Take all the actions that you want to record.

9. Choose ToolsOMacroOStop Recorder, as shown in Figure 24-4, to stop recording your macro.

Macro Project Management
Figure 24-4: When you're finished recording a macro, use the Stop Recorder command.

Was this article helpful?

0 0
Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook

Post a comment