Download presentation
Presentation is loading. Please wait.
Published byAvice Strickland Modified over 9 years ago
1
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft® Excel 2013
2
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. 2
3
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. 3
4
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. A macro is a sequence of commands and keystrokes that automate a routine task. Excel macros are recorded in Visual Basic for Applications programming language (VBA).
5
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. Macros are stored in macro-enabled workbooks. The file name extension for a macro-enabled workbook is xlsm. You can set how macro-enabled workbooks are opened in the Trust Center. Macros must be enabled to be used.
6
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. Viruses and other malware can easily be hidden in macros. You can set your computer to notify you when a workbook has a macro.
7
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. A security warning alerts you when you open a workbook that has macros.
8
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. The Macros button is on the View and the Developer tabs. The Macro dialog box lists existing macro names.
9
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. 9
10
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. Macros can be edited in the Visual Basic Editor. Code window Project Explorer Properties window
11
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. The first lines in a macro include the macro name and comment lines. A subroutine macro is run from within the workbook. Comment lines are preceded by an apostrophe and shown in green. A keyboard shortcut may also be indicated.
12
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. Spaces and punctuation are part of the macro code and should not be changed. Simple format and text changes are relatively easy to determine. You must resave the workbook to save edits made in the Visual Basic Editor.
13
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. You can change the font size by keying a new size. Add text by clicking to place an insertion point and keying the new data.
14
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. You can insert your own comment lines in a macro. Key an apostrophe to precede the line.
15
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. Choose File and Print from the Visual Basic Editor menu to print macro code.
16
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. 16
17
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. Macros are recorded and saved in a macro-enabled workbook. You first name a macro and then perform the actual steps for the task. A macro is usable whenever the workbook is open.
18
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. The Macros button is on the View command tab. The Code group is on the Developer command tab. There is a Record Macro button in the status bar.
19
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. Macros names must begin with a letter. Macro names cannot include spaces or special characters. All macro shortcuts include [Ctrl]. You should use uppercase letters for keyboard shortcuts.
20
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. In the Record Macro dialog box, you can name the macro, assign a shortcut, and key a description.
21
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. Special-purpose macros are used with one workbook and should be stored in that workbook. General-purpose macros can be stored in a workbook that contains only macros. Anytime this workbook is open, any other open workbook can use its macros.
22
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. While you are recording a macro, the status bar shows a Stop Recording button. Click this button when you complete the steps. There is a Stop Recording button on the Developer command tab.
23
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. Macros are recorded with absolute or relative references. The Relative References button is an on/off toggle. With relative references, the macro records pointer movement commands. You must position the pointer before running the macro.
24
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. With absolute references, the macro records ending cell addresses. Pointer movement is not recorded. The pointer can be anywhere when the macro is run.
25
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. 25
26
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. A form control in an object that directs tasks or commands. A button is a form control. A button, when clicked, runs the macro that is assigned to it. Use the Insert Controls button on the Developer command tab.
27
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. Draw the button control on the worksheet.
28
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved.
29
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. 29
30
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. A macro workbook contains only macros. Open this workbook each time you start Excel. Use its macros in any other open workbook. You can set a workbook to open each time you start Excel in the General group on the Advanced tab in Excel Options.
31
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. Macros can include format commands set from the dialog box or the Ribbon.
32
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. Macros are stored in modules in the Visual Basic Editor. A module can have several macros.
33
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. You can create a documentation sheet for a macro workbook. Run the macro to displays its results and key a description.
34
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. You can copy macro code from the Visual Basic Editor into a worksheet as documentation.
35
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. 35
36
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. General-purpose macros that should be available at all times should be stored in the Personal Macro Workbook, Personal.xlsb, in the XLStart folder. The Personal Macro Workbook opens as a hidden workbook each time you start Excel.
37
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. The Personal Macro workbook is hidden. You can unhide it for editing if necessary.
38
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. Personal.xlsb can be edited in the Visual Basic Editor. The path to Personal.xlsb in Windows 7 is C:\Users\UserName\AppData\Roaming\Microsoft\Excel\XLSTART Some of these folders may be hidden.
39
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. A macro is a sequence of commands and keystrokes, converted to Visual Basic for Applications (VBA) code as you record them. In the Trust Center, you can set how a workbook with macros opens. You must enable macros to run them.
40
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. You can run a macro from the View tab, from the Developer tab, with a keyboard shortcut, or from a form control. Use the Visual Basic Editor to review and edit macro code. Press [Alt]+[F11] to open the Visual Basic Editor. You can print macro code from the Visual Basic Editor.
41
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. Subroutine macros start with the word “Sub” followed by the macro name. Subroutine macros end with “End Sub.” Macros are stored in workbooks. Delete a macro if you no longer need it.
42
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. Macro names must begin with a letter and cannot use spaces or special characters. Keyboard shortcuts should include [Shift] so that you do not override Excel’s own shortcuts. You can record macros with relative or absolute cell references.
43
a lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. Use the Button form control on the Developer tab to draw a button shape. You can assign a macro to a button. A macro workbook can include only macros and documentation. A macro workbook can be hidden so that it is not mistakenly used as a regular workbook.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.