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

Preview:

Citation preview

Chapter 11: Introduction to the Visual Basic Environment

Spreadsheet-Based Decision Support Systems

Prof. Name name@email.comPosition (123) 456-7890University Name

2

Overview

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

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.

4

Visual Basic Editor

Project Explorer

Properties Window

Code Window

Immediate and Watch Windows

VBE Toolbars

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

6

Visual Basic Editor (cont’d)

The Visual Basic Editor windows:

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.

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

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

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.

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.

12

The Object Browser

Properties, Methods and Events

Libraries, Classes, and Members

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.

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.

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.

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.

17

Additional Links

(place links here)

Recommended