ME 142 Engineering Computation I Macros. Key Concepts Macro Overview Recording a Macro Running a...

23
ME 142 Engineering Computation I Macros

Transcript of ME 142 Engineering Computation I Macros. Key Concepts Macro Overview Recording a Macro Running a...

ME 142Engineering Computation I

Macros

Key Concepts

Macro Overview

Recording a Macro

Running a Macro

Editing a Macro

Using Controls

Macro Overview

Macro Overview

A macro is a short program or set of recorded keystrokes

Stored as VBA program Great for repetitive tasks Can be edited Great way to learn new VBA functions

Recording a Macro

Recording a Macro

Recording of a macros can be launched from the View and Developer tabs or the lower left of the spreadsheet window

Recording a Macro Select Use Relative References button, if

desired, prior to recording macro

Recording a Macro Prior to recording

the macro, a dialog box is displayed

Note in particular: Shortcut key Storage location

Ending a Macro Recording

Use the Stop Recording button on from the View or Developer tabs or the lower left of the spreadsheet window

Running a Macro

Running a Macro

Click on Macro from the View or Developer ribbons to list available macros

May also use previously assigned shortcut key combination to launch macro

Editing a Macro

Editing a Macro

Edit a Macro as you would any VBA program

Alternately may launch editor by clicking on Macro in the View or Developer ribbons and selecting Edit

Example Problem Convert a temperature from F to C

Both F and C temperatures should appear in adjacent cells when the macro is complete

Using Controls

Using Controls Form Controls can be used to facilitiate

getting input or running a VBA program Example:

Button – facilitate running VBA program

Using Controls Continued

Forms controls can also be used in Excel spreadsheets and custom dialog boxes

Today we’ll look at their use directly in a spreadsheet

Later will see how they can be used in custom dialog boxes

Using Controls Continued

Forms controls are available on the Developer tab, under Insert

Spin Button

Used to increase/decrease the value of a cell May link directly to a cell After placing control, right click to format

control

Scroll Bar

Used to increase/decrease the value of a cell May position either horizontally or vertically

by dragging in that direction After placing control, right click to format

control

Review Questions

ReviewQuestion

In Excel, a macro is always created as a:A. VBA Sub

B. VBA Function

C. VBA Macro

D. May be either A or B

E. None of the above

Homework Help ‘n Hints