Creating and Modifying Macros


The first step of creating a macro is to plan the process you want to automate. Computers today are quite fast, so adding an extra step that doesn't affect the outcome of a process doesn't slow you down noticeably, but leaving out a step means you will need to rerecord your macro. After you plan your process, you can create a macro by clicking the View tab and then, in the Macros group, clicking the Macros button down arrow. From the list that appears, click Record Macro. When you do, the Record Macro dialog box appears.

After you type the name of your macro in the Macro Name box, click OK. You can now perform the actions you want Excel 2007 to repeat later; when you're done, click the View tab and then, in the Macros group, click the Macros button down arrow. From the list that appears, click Stop Recording to add your macro to the list of macros available in your workbook.

To modify an existing macro, you can simply delete the macro and rerecord it. Or if you just need to make a quick change, you can open it in the Visual Basic Editor and add to or change the macro's instructions. To delete a macro, open the Macro dialog box, click the macro you want to delete, and then click Delete.

In this exercise, you record a macro that removes the bold formatting from four cells, modify the macro to remove the bold formatting from a fifth cell, and then save the file.

USE the Yearly Sales Summary workbook in the practice file folder for this topic. This practice file is located in the My Documents\Microsoft Press\Excel SBS\Macros folder.

OPEN the Yearly Sales Summary workbook.


1.

If necessary, on the Message Bar, click Options.

The Microsoft Office Security Options dialog box appears.

2.

Select the Enable this content option button.

3.

Click OK.

The security warning disappears, and macros are enabled.

4.

On the View tab, in the Macros group, click the Macros button down arrow and then click Record Macro.

The Record Macro dialog box appears.

5.

In the Macro name box, delete the existing name, and then type RemoveHighlight.

6.

Click OK.

The Record Macro dialog box disappears.

7.

Select the cell range C4:C7, and then, on the Home tab, in the Font group, click the Bold button.

8.

On the View tab, in the Macros group, click the Macros button down arrow and then click Stop Recording.

Excel 2007 stops recording the macro.

9.

On the View tab, in the Macros group, click the Macros button down arrow and then click View Macros.

The Macro dialog box appears.

10.

In the Macro name section, click RemoveHighlight and then click Edit.

The Visual Basic Editor appears.

11.

Click at the end of the line just above End Sub, press , and type Range("C9"). Select, and press .

This macro statement selects cell C9.

12.

Type Selection.Font.Bold = False and then press .

This macro statement removes bold formatting from the selected cell (C9).

13.

On the Standard toolbar of the Visual Basic Editor, click the Save button to save your change.

14.

Click the Close button of the Microsoft Visual Basic Editor window. The Visual Basic Editor disappears.

15.

On the View tab, in the Macros group, click the Macros button down arrow and then click View Macros.

The Macro dialog box appears.

16.

Click Highlight and then click Run.

The contents of cells C4, C5, C6, C7, and C9 appear in bold type.

17.

On the View tab, in the Macros group, click the Macros button down arrow and then click View Macros.

The Macro dialog box appears.

18.

Click RemoveHighlight and then click Run.

The contents of cells C4, C5, C6, C7, and C9 appear in regular type.

19.

On the Quick Access Toolbar, click the Save button.

Excel 2007 saves your workbook.

CLOSE the Yearly Sales Summary workbook.





MicrosoftR Office ExcelR 2007 Step by Step
MicrosoftВ® Office ExcelВ® 2007 Step by Step (Step By Step (Microsoft))
ISBN: 073562304X
EAN: 2147483647
Year: 2004
Pages: 143
Authors: Curtis Frye

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net