visual basic is the language for programming in word, access,& excel is the “environment”...

14
Visual Basic Is the language for programming in Word, Access,& Excel Is the “Environment” in which the programming is done (called the Integrated Development Environment or IDE)

Upload: hannah-sanders

Post on 13-Dec-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Visual Basic  Is the language for programming in Word, Access,& Excel  Is the “Environment” in which the programming is done (called the Integrated Development

Visual Basic

Is the language for programming in Word, Access,& Excel

Is the “Environment” in which the programming is done (called the Integrated Development Environment or IDE)

Page 2: Visual Basic  Is the language for programming in Word, Access,& Excel  Is the “Environment” in which the programming is done (called the Integrated Development

Visual Basic

Objects / Properties / Methods

Object

Property

Method

Noun

Adjective

Verb

Page 3: Visual Basic  Is the language for programming in Word, Access,& Excel  Is the “Environment” in which the programming is done (called the Integrated Development

Visual Basic

Range (“A3”).select

Range is an object

select is a method

(“A3”) is a modifier for the object

Note that object separated from method by a .

Page 4: Visual Basic  Is the language for programming in Word, Access,& Excel  Is the “Environment” in which the programming is done (called the Integrated Development

Activesheet.name

Activesheet is an object

name is a property

Visual Basic

The result is the name of the active sheet

Page 5: Visual Basic  Is the language for programming in Word, Access,& Excel  Is the “Environment” in which the programming is done (called the Integrated Development

Visual Basic

All objects have properties

Most objects have methods

Will work with only a few of the many objects, methods and properties

Will introduce them as needed

Page 6: Visual Basic  Is the language for programming in Word, Access,& Excel  Is the “Environment” in which the programming is done (called the Integrated Development

Visual Basic

Some of the objects

WorkbookWorksheetActiveSheetRangeFormChart

Note --- a “Cell” is not an object, but is a type of range object

Page 7: Visual Basic  Is the language for programming in Word, Access,& Excel  Is the “Environment” in which the programming is done (called the Integrated Development

Visual Basic

And to further confuse the issue objects can have objects as properties

And objects can be grouped into collections

Workbook = collection of worksheets

Page 8: Visual Basic  Is the language for programming in Word, Access,& Excel  Is the “Environment” in which the programming is done (called the Integrated Development

Visual Basic -- The Environment

From Excel --- toggle with alt F11

Notice 3 parts to the IDE

The Project areaThe Properties area

The blank (or work area)

We will use primarily the properties and work areas

Page 9: Visual Basic  Is the language for programming in Word, Access,& Excel  Is the “Environment” in which the programming is done (called the Integrated Development

Macros are a type of VBA module

“Recorded Macros” are exactly that A record of the key strokes

converted to VB code

Page 10: Visual Basic  Is the language for programming in Word, Access,& Excel  Is the “Environment” in which the programming is done (called the Integrated Development

Keyboard Macros

Quick way to develop a macro

Captures keystrokesAssigns a name & shortcut

Two places to store

Current workbookPersonal workbook

Page 11: Visual Basic  Is the language for programming in Word, Access,& Excel  Is the “Environment” in which the programming is done (called the Integrated Development

Current workbook

Macro only available in the workbook

Stays with the workbook

Personal workbook

Available to all workbooks you create in currentsession.

Does not travel with current workbook

Stored in a special area and needs to be opened.

Page 12: Visual Basic  Is the language for programming in Word, Access,& Excel  Is the “Environment” in which the programming is done (called the Integrated Development

Recorded keystrokes macros, if saved in current workbook, are VBA subprograms in the “modules” component of the IDE. Good way to look at how Excel is manipulated.

If saved in the Personal Workbook, will see the Personal Workbook available in the IDE Project window. Are in a module of the Personal workbook

Page 13: Visual Basic  Is the language for programming in Word, Access,& Excel  Is the “Environment” in which the programming is done (called the Integrated Development

Can record macros in two modes:

Absolute address mode – referenced cells are absolute addresses (i.e. $col$row)

Relative address mode – referenced cells are relative to the selected cell when the macro is recorded. That is, cell addresses may change each time macro is run.

Page 14: Visual Basic  Is the language for programming in Word, Access,& Excel  Is the “Environment” in which the programming is done (called the Integrated Development

We will use recorded macros primarily as a way to introduce VBA programming.

But you should be able to find a good use for them – great for repeated tasks.

We will develop a couple of macros today and explore VBA more over the next wLabs.