XL97: Changes to Microsoft Visual Basic for Applications
ID: Q161609
|
The information in this article applies to:
-
Microsoft Excel 97 for Windows
SUMMARY
The user interface for Microsoft Visual Basic for Applications in Microsoft
Excel 97 has changed significantly from the interface for earlier versions
of Microsoft Excel. This article describes the changes in the Visual Basic
for Applications environment in Microsoft Excel 97.
MORE INFORMATION
The components that make up Microsoft Visual Basic for Applications are the
Visual Basic Editor, the forms interface, and the Visual Basic for
Applications language.
The Microsoft Visual Basic Editor
The Microsoft Visual Basic Editor (VBE) uses the familiar programming
interface of Microsoft Visual Basic 4.0 as a base for creating and editing
code. Within the VBE, there are five major elements: Project Explorer,
Property Window, Code Window, Object Browser, and Debugging Tools.
- Project Explorer
Code created for a Microsoft Excel workbook is associated to that
workbook through a project. The Project Explorer is a navigational
and management tool which displays a hierarchical list of each open
project. It also shows each of the components associated with those
projects, such as worksheets, forms, class modules, and references.
- Property Window
The Property Window displays properties for the active object
(UserForm or control). It provides a visual way to set or modify
properties. In earlier versions of Microsoft Excel, most properties
could only be set programmatically. In Microsoft Excel 97, many of
these properties can now be set through the Properties window for an
object. In the Property window, properties may be listed
alphabetically or by category.
- Code Window
Module sheets are no longer available for insertion into a workbook.
Instead, a Code window is provided for each workbook, for individual
worksheets, and for general modules, class modules, and forms. The
Code window includes two drop-down boxes: one (on the left) to
identify the Object with which the code is associated, and one (on
the right) to identify the Procedure.
To activate a Code window, use one of the following methods:
- Double-click the object for which you want to write or edit
code.
-or-
- Click the object once to select it, and then click Code on the
View menu or press F7.
-or-
- Using the right mouse button, click the object, and then click
View Code on the shortcut menu.
For backward compatibility, Microsoft Excel 4.0 Macro sheets can
still be inserted and will run normally. Microsoft Excel 5.x and 7.x
module sheets are hidden and the code on them is transferred to code
modules in Visual Basic for Applications. This code will also run
normally.
- Object Browser
The Object Browser is similar to the Object Browser in earlier
versions of Microsoft Excel with additional functionality including:
- Differentiates between built-in properties, methods, and
user-defined procedures.
- Indicates which items are globally accessible.
- Shows function return types, parameter names and types, and user
defined types and constants.
- Has a modeless window so that other activities can be carried
out while the browser is displayed.
- Allows for viewing of all available type libraries.
- Includes a Find feature to search for objects across libraries.
- Debugging Tools
The debugging tools in VBE include the familiar Watch window and
Immediate window in addition to:
- An auto variables window which allows you to automatically see
the values of all variables and expressions within a few lines
of the current line of execution.
- A local variables window which includes a call stack browser
which allows you to jump to variable and procedure definitions
and references.
- Margin Indicators to visually indicate current lines of
execution.
- Ability to tile the debug window.
One final change is that VBE operates in either Run Mode or Design Mode.
Run mode is the default mode when a project is opened and is transparent to
the user. Design Mode must be entered explicitly by clicking on the Design
Mode button or clicking the Design Mode command on the Run menu. The main
benefit of Design Mode is that it allows programmers to stop event
handling routines from running automatically.
The Forms Interface
Earlier versions of Microsoft Excel used Dialogs on Dialog sheets to
create custom forms. In Microsoft Excel 97, Dialog sheets are still
available for backward computability. UserForms are now available for
custom forms and can be used in Microsoft Excel 97, Microsoft Word 97, and
Microsoft PowerPoint 97.
The advantages of UserForms are that they:
- Take less time to load, save, and redraw controls.
- Support data binding to cells and ranges.
- Support printing and zooming.
- Include alignment and layout tools, drag-and-drop operations of
controls and in-place editing of captions for advanced form design.
- Support multi-page controls for tab creation.
The Forms toolbar can be customized to display all registered OLE Custom
Controls (OCX) in the system. The Forms toolbar can also have additional
pages, controls can be moved from page to page, the bitmaps for the
controls can be edited, and the tooltips can easily be changed.
Dragging a control from the form back to the toolbar creates a template of
that control on the toolbar. For more information about creating a template
for a control on the Forms toolbar, please see the following article in the
Microsoft Knowledge Base:
Q160473 XL97: How to Create a Template for a Toolbox Control
The Microsoft Visual Basic for Applications Programming Language
- The Language
Microsoft Visual Basic for Applications Programming developed for
Microsoft Office 97 uses Microsoft Visual Basic 4.0 as its foundation.
Many elements found in Visual Basic 4.0 are now incorporated into
Visual Basic for Applications, such as user defined class modules,
user defined collections, and custom properties.
The three member types of all Visual Basic for Applications object
models are Methods, Properties, and Events. Events have been expanded
beyond the Click, Show, and Change events that were available in
earlier versions of Microsoft Excel. Examples of new events are
Activate, BeforeDoubleClick, SheetChange, Open, WindowActivate,
MouseUp, MouseDown, and Calculate.
- Code Behind Objects
Visual Basic for Applications also supports extended objects in
Microsoft Excel 97. An extended object is an object that has code
attached to it. Workbooks and worksheets can have code attached, as
can controls and forms.
Code behind objects uses extended objects to enhance Visual Basic for
Applications programming by:
- Directly and exclusively attaching a code module to an object.
- Directly attaching forms to an object.
- Using Properties and Methods of the object without need for the
name of the object to which the code is attached.
- Providing a unified user model for writing event handling code for
the object and for the controls inside the object.
There are several advantages to code behind objects. Code is moved,
copied, and saved with the object to which it is attached. Simpler
syntax can be used to refer to properties and methods of the objects
because the code is attached to the object. For example, in earlier
versions of Microsoft Excel, if programming code referred to
"Worksheets("Sheet1")" and Sheet1 was renamed to "First Sheet", all
code referring to Sheet1 would generate an error. With code attached
to the object, when Sheet1 is renamed, the code attached to it still
runs without you having to edit the code.
REFERENCES
For more information about new features, click the Index tab in Microsoft
Excel Help, type the following text
new, features
and then double-click the selected text to go to the "What's new in
Microsoft Excel 97" topic.
Additional query words:
XL97 97 VBA VBE VB Editor project explorer
Keywords : kbprg kbui kbdta xlui KbVBA
Version : WINDOWS:97
Platform : WINDOWS
Issue type :
|