Download presentation
Presentation is loading. Please wait.
Published byPhillip Holmes Modified over 8 years ago
1
McGraw-Hill/Irwin The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft Excel 2002 Using Macros Lesson 5
2
The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5-2 McGraw-Hill/Irwin Skills Introducing Macros Recording a Macro Running a Macro Editing a Macro Adding and Deleting a Macro from a Toolbar Adding and Deleting a Macro from a Menu Copying Macros to Other workbooks
3
The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5-3 McGraw-Hill/Irwin Introducing Macros When working with a spreadsheet the user or designer may need to repeat a series of actions –Across cells –To perform a particular task An overall task needs to be performed easily, quickly, accurately
4
The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5-4 McGraw-Hill/Irwin Introducing Macros Series of complicated steps for each cell can be "recorded" –Includes mouse click commands –Keystrokes Then the macro is "played back" for each cell or range desired
5
The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5-5 McGraw-Hill/Irwin Introducing Macros Name the macro –Name must start with a letter –Cannot contain spaces –Should not conflict with a cell name
6
The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5-6 McGraw-Hill/Irwin Introducing Macros Identify the steps involved –Advisable to write down steps ahead of time –Keeps from missing steps –Avoids extra, unneeded steps
7
The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5-7 McGraw-Hill/Irwin Introducing Macros Storing a Macro –May be part of current workbook or … –Stored in a different workbook Could be a workbook containing only macros –Plan ahead as to where this will be
8
The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5-8 McGraw-Hill/Irwin Recording a Macro Identify the steps of the macro Set up the conditions under which it will run Note – record actions carefully –All user actions (including mistakes) will be recorded –Both typing mistakes and their corrections will be recorded
9
The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5-9 McGraw-Hill/Irwin Recording a Macro Preparing to record a Macro –Click on Tools, then Options –Options dialog box appears –Click the Security Tab –Click on Macro Security Since we are recording our own macros, we will use the Low option –Click OK here –Click OK on Options
10
The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5-10 McGraw-Hill/Irwin Recording a Macro To record –Click on Tools, then Macro, then Record a New Macro
11
The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5-11 McGraw-Hill/Irwin Recording a Macro Record Macro dialog box appears Name the macro Specify the shortcut key Document the macro, describing what it does Click OK and Stop Recording toolbar appears
12
The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5-12 McGraw-Hill/Irwin Recording a Macro Perform the steps required by the macro –Click on a cell –Type text or formulas –Click on menu commands Copy, Paste, Insert, Print, etc. –Time spent between mouse clicks or keystrokes is not recorded – just the actions When done click on the Stop Recording button –Toolbar will close … macro has been recorded
13
The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5-13 McGraw-Hill/Irwin Running a Macro After a macro is recorded –Can be run from any workbook –Performs the recorded actions on the active workbook Recommendations –Save all open files –Then run the new macro To stop a macro, pres [Esc]
14
The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5-14 McGraw-Hill/Irwin Running a Macro Click on Tools, then Macro – dialog box appears Choose desired macro Click Run Review results to verify correctness of macro
15
The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5-15 McGraw-Hill/Irwin Editing a Macro Macros are stored in Visual Basic modules –Editing takes place in Visual Basic Editor –This is more efficient than re-recording the macro under the same name Visual Basic Editor –Code window displays instructions –Changing the instructions can be done with minimal knowledge of Visual Basic
16
The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5-16 McGraw-Hill/Irwin Editing a Macro Click on Tools, then Macro – dialog box appears Choose macro to edit Click on Edit Visual Basic Editor opens
17
The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5-17 McGraw-Hill/Irwin Editing a Macro Visual Basic Editor window Code Window Each line of code represents an action recorded for the macro Green text denotes comments; does not affect macro execution
18
The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5-18 McGraw-Hill/Irwin Editing a Macro New Macro Code Newly added code to change value in cell back to original Click X to close Visual Basic Editor window and return to worksheet
19
The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5-19 McGraw-Hill/Irwin Adding and Deleting a Macro from a Toolbar Provides quick and easy access to a macro Button added to toolbar using Customize dialog box When button added to toolbar it is available in all Excel files
20
The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5-20 McGraw-Hill/Irwin Adding and Deleting a Macro from a Toolbar Click Tools, then Customize – dialog box appears Click Commands tab if necessary Choose Macros Note the two custom commands
21
The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5-21 McGraw-Hill/Irwin Adding and Deleting a Macro from a Toolbar Drag the button from the dialog box to the toolbar. –Mouse cursor becomes I beam on toolbar –When mouse button released, icon stays on toolbar I
22
The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5-22 McGraw-Hill/Irwin Adding and Deleting a Macro from a Toolbar Click the Modify Selection button in the dialog box Choose Assign Macro Assign Macro dialog box appears Click on macro to be assigned to button Then OK
23
The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5-23 McGraw-Hill/Irwin Adding and Deleting a Macro from a Toolbar Click Modify Selection again Enter description into Macro name text box –Names the button –Becomes screen tip for the button
24
The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5-24 McGraw-Hill/Irwin Adding and Deleting a Macro from a Toolbar Click the Modify Selection button again Choose Change Button Image Click on desired icon
25
The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5-25 McGraw-Hill/Irwin Adding and Deleting a Macro from a Toolbar Button image may also be edited
26
The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5-26 McGraw-Hill/Irwin Adding and Deleting a Macro from a Menu Macro command may also be added to a dropdown menu Click Tools, then Customize (use the Commands tab) Select Macros This time choose the Custom Menu Item and drag it to desired pulldown menu –Place in desired order in the menu
27
The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5-27 McGraw-Hill/Irwin Adding and Deleting a Macro from a Menu Custom menu item placed in desired menu Use the Modify Selection to change –Delete unneeded command –Name displayed –Add icon if desired
28
The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5-28 McGraw-Hill/Irwin Copying Macros to Other Workbooks Macro created and saved in one workbook –Cannot be used in another workbook unless original workbook is open –Excel must open that workbook Possible to avoid delay –Copy macro from parent workbook to active workbook Use Project Explorer window of Visual Basic Editor window
29
The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5-29 McGraw-Hill/Irwin Copying Macros to Other Workbooks With both macro source and macro destination workbooks open … –Click on Tools, then Macro, then Visual Basic Editor
30
The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5-30 McGraw-Hill/Irwin Copying Macros to Other Workbooks Visual Basic Editor Project Explorer window Click the + to show folder's contents
31
The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5-31 McGraw-Hill/Irwin Copying Macros to Other Workbooks Workbook folders shows macro from other project Currently active project Drag macro module to the destination project
32
The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5-32 McGraw-Hill/Irwin Copying Macros to Other Workbooks Macro is now also an element of the second workbook When the macro is called from the newer workbook –Runs from that workbook –No need to wait for first workbook to open
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.