Changes to Microsoft Visual Basic for Applications (188835)



The information in this article applies to:

  • Microsoft Excel 98 Macintosh Edition

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.
    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.
  • 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:
    • It allows you to differentiate between built-in properties, methods, and user-defined procedures.
    • It indicates which items are globally accessible.
    • It shows you the function return types, parameter names and types, and user defined types and constants.
    • It has a modeless window so that other activities can run while the browser is displayed.
    • It allows you to view all available type libraries.
    • It includes a Find feature that allows you to search for objects across libraries.
  • Debugging Tools
    The debugging tools in Visual Basic Editor include the Immediate window and the following additional tools:
    • Margin Indicators visually indicate current lines of execution.
    • You can tile the Immediate window.
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

  • 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.
  • 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:
    • 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.

Modification Type:MinorLast Reviewed:10/10/2006
Keywords:kbdtacode kbhowto kbProgramming KB188835