16
Chapter 11: Introduction to VBA Spreadsheet-Based Decision Support Systems Prof. Name [email protected] Position (123) 456-7890 University Name

Chapter 11: Introduction to VBA Spreadsheet-Based Decision Support Systems Prof. Name [email protected] Position (123) 456-7890 University Name

Embed Size (px)

Citation preview

Page 1: Chapter 11: Introduction to VBA Spreadsheet-Based Decision Support Systems Prof. Name name@email.com Position (123) 456-7890 University Name

Chapter 11: Introduction to VBA

Spreadsheet-Based Decision Support Systems

Prof. Name [email protected] (123) 456-7890University Name

Page 2: Chapter 11: Introduction to VBA Spreadsheet-Based Decision Support Systems Prof. Name name@email.com Position (123) 456-7890 University Name

2

Overview

11.1 Introduction 11.2 The Visual Basic Editor 11.3 The Object Browser 11.4 Summary

Page 3: Chapter 11: Introduction to VBA Spreadsheet-Based Decision Support Systems Prof. Name name@email.com Position (123) 456-7890 University Name

3

Introduction

The basics of the Visual Basic Editor environment.

The components of the Project Explorer, Properties, and Code Windows.

The difference between a property, method, and event.

The Object Browser.

Page 4: Chapter 11: Introduction to VBA Spreadsheet-Based Decision Support Systems Prof. Name name@email.com Position (123) 456-7890 University Name

4

The Visual Basic Editor

Project Explorer

Properties Window

Code Window

Immediate and Watch Windows

VBE Toolbars

Page 5: Chapter 11: Introduction to VBA Spreadsheet-Based Decision Support Systems Prof. Name name@email.com Position (123) 456-7890 University Name

5

Objects

Objects in Excel include– Workbooks and worksheets– Cells and ranges of cells– Charts

There is an object hierarchy which orders these objects– Workbooks contain worksheets– Worksheets contain ranges– Ranges contain cells

Objects are manipulated in VBA by– Properties = value is given to describe or format the object– Methods = arguments are used to perform an action on the object

Page 6: Chapter 11: Introduction to VBA Spreadsheet-Based Decision Support Systems Prof. Name name@email.com Position (123) 456-7890 University Name

6

Visual Basic Editor

The Visual Basic Editor (VBE) is the environment in which you work with VBA programming code.– Tools > Macro > Visual Basic Editor – VBE icon from VBE Toolbar– ALT + F11

Three main windows in the VBE– Project Explorer– Properties– Code

Two other windows in VBE, used for debugging– Immediate– Watch

Page 7: Chapter 11: Introduction to VBA Spreadsheet-Based Decision Support Systems Prof. Name name@email.com Position (123) 456-7890 University Name

7

Visual Basic Editor (cont)

The Visual Basic Editor windows

Project Explorer

Properties Window

Code Window

Watch Window

Immediate Window

Page 8: Chapter 11: Introduction to VBA Spreadsheet-Based Decision Support Systems Prof. Name name@email.com Position (123) 456-7890 University Name

8

Project Explorer

Lists all projects in any open workbook.

Each workbook has a project, and each project can have several parts– Workbook and worksheets

– Modules

– Forms

Use Insert > Module or Insert > User Form to add a new module or form to the current project; can also use icon from standard toolbar.

Page 9: Chapter 11: Introduction to VBA Spreadsheet-Based Decision Support Systems Prof. Name name@email.com Position (123) 456-7890 University Name

9

Properties Window

Contains detailed information about any selected part of a project in the Project Explorer.

Some basic naming and formatting properties can be modified for worksheets and workbooks.

Properties are very important for user forms– Formatting

– Position

– Picture

– Scrolling

– Behavior

Page 10: Chapter 11: Introduction to VBA Spreadsheet-Based Decision Support Systems Prof. Name name@email.com Position (123) 456-7890 University Name

10

Code Window

Displays the VBA code for the highlighted part of a project in the Project Explorer.

When macros are recorded they are simultaneously created as VBA code in the Visual Basic Editor.

There are three types of macros or procedures – Sub procedures

– Function procedures

– Event procedures

Page 11: Chapter 11: Introduction to VBA Spreadsheet-Based Decision Support Systems Prof. Name name@email.com Position (123) 456-7890 University Name

11

Immediate and Watch Windows Both of these windows are used for debugging.

Immediate Window executes whatever is entered immediately.

Watch Window displays values of inserted variables.

Use the View menu option to view or hide any window.

Page 12: Chapter 11: Introduction to VBA Spreadsheet-Based Decision Support Systems Prof. Name name@email.com Position (123) 456-7890 University Name

12

The Object Browser

Properties and Methods

Libraries, Classes, and Members

Page 13: Chapter 11: Introduction to VBA Spreadsheet-Based Decision Support Systems Prof. Name name@email.com Position (123) 456-7890 University Name

13

Object Browser

Provides a list of properties and methods of all Excel objects which may be manipulated in VBA.

There are larger categories into which various objects are grouped– Classes = groups of related objects

– Libraries = collections of VBA and Excel object classes

– Members = properties, methods, and constants of a selected class of objects

View > Object Browser or icon from standard toolbar.

Page 14: Chapter 11: Introduction to VBA Spreadsheet-Based Decision Support Systems Prof. Name name@email.com Position (123) 456-7890 University Name

14

Object Browser (cont’d)

All classes containing the searched object are shown in the top window.

All members of a selected class are shown below.

Page 15: Chapter 11: Introduction to VBA Spreadsheet-Based Decision Support Systems Prof. Name name@email.com Position (123) 456-7890 University Name

15

Summary

The Visual Basic Editor (VBE) is the environment in which you work with VBA programming code.

There are three main windows in VBE: the Code Window, the Project Explorer, and the Properties Window.

The Object Browser provides a list of properties and methods of all Excel objects that may be manipulated in VBA.

Properties are the physical descriptions of all Excel objects, and the description of the particular property is called the value of the property.

Methods are the actions that can be performed on the object. The elements of a method statement are called the arguments of the method.

Page 16: Chapter 11: Introduction to VBA Spreadsheet-Based Decision Support Systems Prof. Name name@email.com Position (123) 456-7890 University Name

16

Additional Links

(place links here)