Excel Lesson 14 Creating and Using Macros Microsoft Office 2010 Advanced Cable / Morrison 1.

Post on 23-Dec-2015

215 views 0 download

Tags:

Transcript of Excel Lesson 14 Creating and Using Macros Microsoft Office 2010 Advanced Cable / Morrison 1.

Excel Lesson 14Creating and Using Macros

Microsoft Office 2010 Advanced

Cable / Morrison1

Ex

cel L

es

son

14

Cable / Morrison Microsoft Office 2010 Advanced2

Objectives

Understand macros. Review macro security settings. Record a macro. Save a macro as a macro-enabled workbook. Run a macro.

22

Ex

cel L

es

son

14

Cable / Morrison Microsoft Office 2010 Advanced

Objectives (continued)

Edit a macro. Create a button. Align and format a button. Open a macro-enabled workbook.

3

Ex

cel L

es

son

14

Cable / Morrison Microsoft Office 2010 Advanced4

Vocabulary

44

button code macro virus

Ex

cel L

es

son

14

Cable / Morrison Microsoft Office 2010 Advanced5

Introduction

A macro automates a common, repetitive task you perform in Excel.

In this lesson, students will learn how to:– Create macros– Run a macro – Make changes to a macro– Add a macro to a button

Ex

cel L

es

son

14

Cable / Morrison Microsoft Office 2010 Advanced

Understanding Macros

A macro records a series of steps that you do frequently, such as formatting text.

Visual Basic for Applications (or VBA) is the program used to create macros.

Code refers to the macro actions formatted in easy-to-read sentences.

6

Ex

cel L

es

son

14

Cable / Morrison Microsoft Office 2010 Advanced

Reviewing Macro Security Settings

Macros are susceptible to a virus attack. A virus is a computer program that is

designed to reproduce by copying itself and attaching to other programs in a computer.– Can cause extreme damage to data

You can set one of four macro security levels in Excel.

7

Ex

cel L

es

son

14

Cable / Morrison Microsoft Office 2010 Advanced

Reviewing Macro Security Settings (continued)

Macro security level options

8

Ex

cel L

es

son

14

Cable / Morrison Microsoft Office 2010 Advanced

Reviewing Macro Security Settings (continued)

Trust Center dialog box

9

Ex

cel L

es

son

14

Cable / Morrison Microsoft Office 2010 Advanced

Recording a Macro

To begin recording a macro:– Click the Record Macro button in the Code group

on the Developer tab.– Fill out the options in the Record Macro dialog

box.– Click OK to close the dialog box; the macro will

start recording.

10

Ex

cel L

es

son

14

Cable / Morrison Microsoft Office 2010 Advanced

Recording a Macro (continued)

Record Macro dialog box

11

Ex

cel L

es

son

14

Cable / Morrison Microsoft Office 2010 Advanced

Saving a Workbook as a Macro-Enabled Workbook

The file extension .xlsm is used for a macro-enabled workbook.

A macro-enabled workbook lets you save a macro in the workbook and run the macro.

You can save an ordinary Excel workbook as a macro-enabled workbook using the Save As command.

12

Ex

cel L

es

son

14

Cable / Morrison Microsoft Office 2010 Advanced

Saving a Workbook as a Macro-Enabled Workbook (continued)

Save As dialog box

13

Ex

cel L

es

son

14

Cable / Morrison Microsoft Office 2010 Advanced

Running a Macro

After a macro is created, it is ready to use. Excel provides different ways to run a macro:

– Use a shortcut key combination if one was created in the Record Macro dialog box.

– On the Developer tab in the Code group, select the Macros button.

The Macro dialog box appears. Click the macro you want and click the Run button.

14

Ex

cel L

es

son

14

Cable / Morrison Microsoft Office 2010 Advanced

Editing a Macro

Macros are easy to edit. To edit a macro, you need to make changes

to the VBA code. The code word Sub indicates the start of the

macro. The code End Sub signals the end of the

macro.

15

Ex

cel L

es

son

14

Cable / Morrison Microsoft Office 2010 Advanced

Editing a Macro (continued)

Example of a macro in VBA code

16

Ex

cel L

es

son

14

Cable / Morrison Microsoft Office 2010 Advanced

Editing a Macro (continued)

Making edits to the Formats macro

17

Ex

cel L

es

son

14

Cable / Morrison Microsoft Office 2010 Advanced

Creating a Button

A button is called a control.– Controls the actions that are assigned to it

When you create a button, you are asked to assign a macro to it.

When you click the button, the macro will run.

18

Ex

cel L

es

son

14

Cable / Morrison Microsoft Office 2010 Advanced

Creating a Button (continued)

Worksheet with both buttons added

19

Ex

cel L

es

son

14

Cable / Morrison Microsoft Office 2010 Advanced

Aligning and Formatting Buttons

To select a button with an assigned macro, right-click the button.– A shortcut menu appears.

With more than one button selected, the Format tab appears on the Ribbon.– Format tab has options to make changes to the

buttons, such as aligning buttons.

20

Ex

cel L

es

son

14

Cable / Morrison Microsoft Office 2010 Advanced

Aligning and Formatting Buttons (continued)

Alignment options

21

Ex

cel L

es

son

14

Cable / Morrison Microsoft Office 2010 Advanced

Aligning and Formatting Buttons (continued)

You can right-click a button and choose Format Control from the shortcut menu.

22

Format Control dialog box

Ex

cel L

es

son

14

Cable / Morrison Microsoft Office 2010 Advanced

Opening a Macro-Enabled Workbook

When a workbook with macros is opened, a security warning appears on the Message Bar.– The warning is displayed whenever the Disable all

macros with notification option is chosen. To enable the macros, click the Enable

Content button on the Message Bar.

23

Ex

cel L

es

son

14

Cable / Morrison Microsoft Office 2010 Advanced

Opening a Macro-Enabled Workbook (continued)

Message Bar with security warning

24

Ex

cel L

es

son

14

Cable / Morrison Microsoft Office 2010 Advanced

Summary

In this lesson, you learned: Macros can automate frequently used tasks. You can review and change macro security

settings. You can record a macro. A workbook can be saved as a macro-

enabled workbook.

25

Ex

cel L

es

son

14

Cable / Morrison Microsoft Office 2010 Advanced

Summary (continued)

After a macro is created, you can run the macro.

If changes need to be made to a macro, you can edit the macro.

Buttons are a type of form control that have a macro assigned to them.

26

Ex

cel L

es

son

14

Cable / Morrison Microsoft Office 2010 Advanced

Summary (continued)

Buttons can be aligned and formatted. When you open a macro-enabled workbook,

you can enable the workbook contents and run any macros in the workbook.

27