Microsoft KB Archive/188835

= Changes to Microsoft Visual Basic for Applications =

Article ID: 188835

Article Last Modified on 10/10/2006

-

APPLIES TO


 * Microsoft Excel 98 for Macintosh

-



This article was previously published under Q188835



SUMMARY
The user interface for Microsoft Visual Basic for Applications in Microsoft Excel 98 has changed significantly from earlier versions of Microsoft Excel. This article describes the changes in the Visual Basic for Applications environment in Microsoft Excel 98 Macintosh Edition.



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 uses the programming interface of Microsoft Visual Basic 4.0 as a base for creating and editing code. Within the Visual Basic Editor, there are five major elements: Project Explorer, Property Window, Code Window, Object Browser, and Debugging Tools.  Project Explorer

When you create code for a Microsoft Excel workbook, it is associated to that workbook through a project. You can use the Project Explorer as a navigational and management tool to display a hierarchical list of each open project. It shows you 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 (user form or control). In earlier versions of Microsoft Excel, you must programmatically set most properties; however, in Microsoft Excel 98, you can set many of these properties through the Properties window. In the Property window, properties may be listed alphabetically or by category. Code Window

You can no longer insert module sheets into a workbook. In Microsoft Excel 98, a Code window is provided for each workbook, for individual worksheets, and for general modules, class modules, and forms. The Code window includes two list boxes: one (left) to identify the object with which the code is associated, and one (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. Click to select the object. On the View menu, click Code (or press F7). Press Control and click the object, and then click View Code on the shortcut menu.</ul>

For compatibility with earlier versions of Microsoft Excel, you can insert and run Microsoft Excel 4.0 Macro sheets in a workbook. Microsoft Excel 5.x and 7.x module sheets are hidden in the workbook interface and the code on them is transferred to code modules in the Visual Basic Editor. This code will also run normally.</li> Object Browser

The Object Browser in Microsoft Excel 98 is similar to the Object Browser in earlier versions of Microsoft Excel with the following functionality additions: <ul> It allows you to differentiate between built-in properties, methods, and user-defined procedures.</li> It indicates which items are globally accessible.</li> It shows you the function return types, parameter names and types, and user defined types and constants.</li> It has a modeless window so that other activities can run while the browser is displayed.</li> It allows you to view all available type libraries.</li> It includes a Find feature that allows you to search for objects across libraries.</li></ul> </li> Debugging Tools

The debugging tools in Visual Basic Editor include the Immediate window and the following additional tools: <ul> Margin Indicators visually indicate current lines of execution.</li> You can tile the Immediate window.</li></ul> </li></ul>

The Visual Basic Editor operates in run mode or design mode. Run mode is the default mode when a project is opened and is transparent to the user. Design mode can be entered by clicking the Design Mode button, or by 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 Dialog sheets to create custom forms. In Microsoft Excel 98, you can use dialog sheets for compatibility with earlier versions of Microsoft Excel; however, you can now use user forms to create custom forms that you can use in Microsoft Excel 98, Microsoft Word 98, and Microsoft PowerPoint 98.

The following is a list of advantages of using user forms:
 * They take less time to load, save, and redraw controls.
 * They support printing and zooming.
 * They include alignment and layout tools, drag-and-drop operations of controls, and in-place editing of captions for advanced form design.
 * They support multi-page controls for tab creation.

The Microsoft Visual Basic for Applications Programming Language
<ul> The Language Microsoft Visual Basic for Applications Programming developed for Microsoft Office 98 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.</li> Code Behind Objects Visual Basic for Applications also supports extended objects in Microsoft Excel 98. An extended object is an object that has code attached to it. You can attach code to Workbooks and worksheets.

Code behind objects uses extended objects to enhance Visual Basic for Applications programming by: <ul> Directly and exclusively attaching a code module to an object.</li> Directly attaching forms to an object.</li> Using Properties and Methods of the object without need for the name of the object to which the code is attached.</li> Providing a unified user model for writing event handling code for the object and for the controls inside the object.</li></ul>

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.</li></ul>

Additional query words: XL98 VBA VBE VB Editor project explorer

Keywords: kbdtacode kbhowto kbprogramming KB188835

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.