OV 1 - 1 Copyright © 2011 Element K Content LLC. All rights reserved. Create a Macro with the...

19
OV 1 - 1 ght © 2011 Element K Content LLC. All rights reserved. Create a Macro with the Macro Recorder Edit a Macro Debug a Macro Customize the Quick Access Toolbar and Hotkeys Working with Macro Security Developing Macros

Transcript of OV 1 - 1 Copyright © 2011 Element K Content LLC. All rights reserved. Create a Macro with the...

Page 1: OV 1 - 1 Copyright © 2011 Element K Content LLC. All rights reserved.  Create a Macro with the Macro Recorder  Edit a Macro  Debug a Macro  Customize.

OV 1 - 1Copyright © 2011 Element K Content LLC. All rights reserved.

Create a Macro with the Macro Recorder Edit a Macro Debug a Macro Customize the Quick Access Toolbar and Hotkeys Working with Macro Security

Developing Macros

Page 2: OV 1 - 1 Copyright © 2011 Element K Content LLC. All rights reserved.  Create a Macro with the Macro Recorder  Edit a Macro  Debug a Macro  Customize.

OV 1 - 2Copyright © 2011 Element K Content LLC. All rights reserved.

Object-Oriented Programming

Modeled like real-time objectModeled like real-time object

Information associated with an objectInformation associated with an object

Page 3: OV 1 - 1 Copyright © 2011 Element K Content LLC. All rights reserved.  Create a Macro with the Macro Recorder  Edit a Macro  Debug a Macro  Customize.

OV 1 - 3Copyright © 2011 Element K Content LLC. All rights reserved.

Sub font2Arial() Cells.Select Selection.Font.Name = "Arial"End Sub

Macros

Code that accomplishesfrequently repeated taskCode that accomplishesfrequently repeated task

Unique macro nameUnique macro name

Page 4: OV 1 - 1 Copyright © 2011 Element K Content LLC. All rights reserved.  Create a Macro with the Macro Recorder  Edit a Macro  Debug a Macro  Customize.

OV 1 - 4Copyright © 2011 Element K Content LLC. All rights reserved.

Macro Options

Page 5: OV 1 - 1 Copyright © 2011 Element K Content LLC. All rights reserved.  Create a Macro with the Macro Recorder  Edit a Macro  Debug a Macro  Customize.

OV 1 - 5Copyright © 2011 Element K Content LLC. All rights reserved.

The Macro Recorder

Start recordingStart recording

Perform tasks in the worksheet

Perform tasks in the worksheet

Reusable generated macro code

Reusable generated macro code

Page 6: OV 1 - 1 Copyright © 2011 Element K Content LLC. All rights reserved.  Create a Macro with the Macro Recorder  Edit a Macro  Debug a Macro  Customize.

OV 1 - 6Copyright © 2011 Element K Content LLC. All rights reserved.

Personal Macro Workbook

Storage location that any

Excel workbook can access

Storage location that any

Excel workbook can access

Page 7: OV 1 - 1 Copyright © 2011 Element K Content LLC. All rights reserved.  Create a Macro with the Macro Recorder  Edit a Macro  Debug a Macro  Customize.

OV 1 - 7Copyright © 2011 Element K Content LLC. All rights reserved.

Visual Basic Editor

Standard toolbar Standard toolbar

Object BrowserObject Browser

Code windowCode window

Project ExplorerProject

Explorer

Properties window

Properties window

Immediatewindow

Immediatewindow

Page 8: OV 1 - 1 Copyright © 2011 Element K Content LLC. All rights reserved.  Create a Macro with the Macro Recorder  Edit a Macro  Debug a Macro  Customize.

OV 1 - 8Copyright © 2011 Element K Content LLC. All rights reserved.

Modules

Code window displaying macros in Module1

Code window displaying macros in Module1

Module1 selected in Project ExplorerModule1 selected

in Project Explorer

Page 9: OV 1 - 1 Copyright © 2011 Element K Content LLC. All rights reserved.  Create a Macro with the Macro Recorder  Edit a Macro  Debug a Macro  Customize.

OV 1 - 9Copyright © 2011 Element K Content LLC. All rights reserved.

The Modules Folder

The Modules folder displayed in Project Explorer

The Modules folder displayed in Project Explorer

Page 10: OV 1 - 1 Copyright © 2011 Element K Content LLC. All rights reserved.  Create a Macro with the Macro Recorder  Edit a Macro  Debug a Macro  Customize.

OV 1 - 10Copyright © 2011 Element K Content LLC. All rights reserved.

Objects

Real-time components used as objects in macros

Real-time components used as objects in macros

Page 11: OV 1 - 1 Copyright © 2011 Element K Content LLC. All rights reserved.  Create a Macro with the Macro Recorder  Edit a Macro  Debug a Macro  Customize.

OV 1 - 11Copyright © 2011 Element K Content LLC. All rights reserved.

Properties

Components that describe an object

Components that describe an object

Page 12: OV 1 - 1 Copyright © 2011 Element K Content LLC. All rights reserved.  Create a Macro with the Macro Recorder  Edit a Macro  Debug a Macro  Customize.

OV 1 - 12Copyright © 2011 Element K Content LLC. All rights reserved.

Methods

Actions that can be performed on an object

Actions that can be performed on an object

Page 13: OV 1 - 1 Copyright © 2011 Element K Content LLC. All rights reserved.  Create a Macro with the Macro Recorder  Edit a Macro  Debug a Macro  Customize.

OV 1 - 13Copyright © 2011 Element K Content LLC. All rights reserved.

Sub AddTotals()'A macro that inserts the SUM function at the bottom of a'column of unknown length.

Dim x As Integer

'Declare the Range objects here: Dim myData As Range Dim myTotal As Range For x = 1 To Worksheets.Count

Worksheets(x).Select

'Set the data range object:Range("A7").SelectSet myData = ActiveCell.CurrentRegion

VBA Comments

Comments explaining purpose of macro

Comments explaining purpose of macro

Comment explaining purpose of code

Comment explaining purpose of code

Apostrophe used to start comment line

Apostrophe used to start comment line

Page 14: OV 1 - 1 Copyright © 2011 Element K Content LLC. All rights reserved.  Create a Macro with the Macro Recorder  Edit a Macro  Debug a Macro  Customize.

OV 1 - 14Copyright © 2011 Element K Content LLC. All rights reserved.

The Debugging Process

Set up environment

Back upRun code with error

Determine problem

Reset dataExecute code line by line

to find the error

Fix code error Retest to ensure error is fixed

Page 15: OV 1 - 1 Copyright © 2011 Element K Content LLC. All rights reserved.  Create a Macro with the Macro Recorder  Edit a Macro  Debug a Macro  Customize.

OV 1 - 15Copyright © 2011 Element K Content LLC. All rights reserved.

Debugging Tools

Tools that start, stop, and reset macro execution

Tools that start, stop, and reset macro execution

Toggle Breakpoint toolToggle Breakpoint tool Step toolsStep tools

Page 16: OV 1 - 1 Copyright © 2011 Element K Content LLC. All rights reserved.  Create a Macro with the Macro Recorder  Edit a Macro  Debug a Macro  Customize.

OV 1 - 16Copyright © 2011 Element K Content LLC. All rights reserved.

Digital Certificates

Unique informationabout the certificate holder

Unique informationabout the certificate holder

Page 17: OV 1 - 1 Copyright © 2011 Element K Content LLC. All rights reserved.  Create a Macro with the Macro Recorder  Edit a Macro  Debug a Macro  Customize.

OV 1 - 17Copyright © 2011 Element K Content LLC. All rights reserved.

Digital Signatures

Digitally signed worksheet cannot be edited

Digitally signed worksheet cannot be edited

Signature iconSignature icon

Page 18: OV 1 - 1 Copyright © 2011 Element K Content LLC. All rights reserved.  Create a Macro with the Macro Recorder  Edit a Macro  Debug a Macro  Customize.

OV 1 - 18Copyright © 2011 Element K Content LLC. All rights reserved.

Macro Security Settings

Page 19: OV 1 - 1 Copyright © 2011 Element K Content LLC. All rights reserved.  Create a Macro with the Macro Recorder  Edit a Macro  Debug a Macro  Customize.

OV 1 - 19Copyright © 2011 Element K Content LLC. All rights reserved.

1. Do you think that the Macro Recorder is a useful tool? Why or why not?

2. How does the Personal Macro Workbook relate to the creation and use of custom toolbars, buttons, and menus?

Reflective Questions