Chapter 11: Introduction to the Visual Basic Environment Spreadsheet-Based Decision Support Systems...

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

Transcript of Chapter 11: Introduction to the Visual Basic Environment Spreadsheet-Based Decision Support Systems...

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

Chapter 11: Introduction to the Visual Basic Environment

Spreadsheet-Based Decision Support Systems

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

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

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 the Visual Basic Environment Spreadsheet-Based Decision Support Systems Prof. Name name@email.com Position (123) 456-7890 University.

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 the Visual Basic Environment Spreadsheet-Based Decision Support Systems Prof. Name name@email.com Position (123) 456-7890 University.

4

Visual Basic Editor

Project Explorer

Properties Window

Code Window

Immediate and Watch Windows

VBE Toolbars

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

5

Visual Basic Editor

The Visual Basic Editor (VBE) is the environment in which you work with VBA programming code.– Developer tab on the Ribbon – ALT + F11

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

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

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

6

Visual Basic Editor (cont’d)

The Visual Basic Editor windows:

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

7

Project Explorer

Lists all projects in any open workbook.

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

– Modules: contain the VBA code for any macro. Standard modules are used for writing general procedures, or sections of code,

to perform different tasks with Excel objects Class modules are used to create new properties and methods for more

advanced coding.

– Forms: the user interface tools in Excel.

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 8: Chapter 11: Introduction to the Visual Basic Environment Spreadsheet-Based Decision Support Systems Prof. Name name@email.com Position (123) 456-7890 University.

8

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 9: Chapter 11: Introduction to the Visual Basic Environment Spreadsheet-Based Decision Support Systems Prof. Name name@email.com Position (123) 456-7890 University.

9

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 two types of procedures – Sub procedures

– Function procedures

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

10

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 11: Chapter 11: Introduction to the Visual Basic Environment Spreadsheet-Based Decision Support Systems Prof. Name name@email.com Position (123) 456-7890 University.

11

VBE Toolbars

There are four toolbars in VBE: – Standard

– Edit

– Debug

– UserForm

The Standard toolbar allows you to– Switch to the Excel window, insert a user form, module, or procedure, and

save our current code modifications.

– Run, pause, or stop your code.

– View the design mode of our form design.

– Perform several standard editing options, such as cut, copy, paste, search, undo, and redo.

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

12

The Object Browser

Properties, Methods and Events

Libraries, Classes, and Members

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

13

Object Browser

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

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

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

Events are actions that are performed on controls.– A control is a user interface object, such as a button or check box.

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

14

Object Browser

There are larger categories into which various objects are grouped– Libraries = collections of

VBA and Excel object classes

– Classes = groups of related objects

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

View > Object Browser or icon from standard toolbar.

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

15

Object Browser (cont’d)

All classes containing the searched object are shown in the Search Results window.

All classes and members of a selected class are shown in the second window.

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

16

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.

Groups of related objects are called classes; collections of VBA and Excel object classes are called libraries; and the properties, methods, and constants of a selected class of objects are known as the members of the class of objects.

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

17

Additional Links

(place links here)