Migrating to the Microsoft Project 98 VBA Object Model

Microsoft Corporation

July 1997

Introduction

Extensive changes have been made to the Microsoft® Project 98 Visual Basic® object model to support new and improved features in the application and to take advantage of the integrated development environment common to all Microsoft Office applications. This paper summarizes these changes to assist in the migration of existing macros from previous versions of Microsoft Project and to aid developers of new macros and custom solutions in identifying changes to Microsoft Visual Basic for Applications (VBA). This paper is not intended to be a comprehensive guide to the new object model. For a complete reference, refer to VBA Help and the VBA Object Browser.

In particular, developers may find that many objects, properties, and methods have been replaced. To provide backward compatibility, most of the replaced components have been hidden rather than removed. Old code that uses these hidden components still works correctly without modification.

Migration of Custom Solutions

Users of custom solutions should note that applications written outside of Microsoft Project (for example, those written in Visual Basic or VBA for other Office applications) that use static (early) binding with the Microsoft Project 95 type library must be modified to work with Microsoft Project 98. Specifically, developers have two options:

Migration of Existing Macros

When run in Microsoft Project 98, macro code created in Microsoft Project 95 or 4.0 may result in errors or other unexpected behavior if not adapted to reflect changes to the Microsoft Project VBA object model. The following sections describe migration issues relating to macros created with earlier versions of Microsoft Project and other behavior that is either unsupported by Microsoft Project 98 or requires some qualification.

Microsoft Project 4.0 and 95 Macros

The following table describes Microsoft Project 4.0 and 95 macros that are either unsupported or the behavior of which is modified by Microsoft Project 98.

Macro, Component,
or Behavior

Status or Qualification
AcceptAllUpdates This macro is not supported in Microsoft Project 98.
CreatePivotTables This macro is made obsolete by the new Save to PivotTable feature, available in the Save As dialog box.

Although this macro continues to run against Microsoft Excel 95, it does not run against Microsoft Excel 97. The macro assumes that Microsoft Excel workbooks have a default of at least five worksheets. Excel 95 has 16, but Excel 97 has only three. The macro has also been hard coded to search for the Excel 5/Excel 95 type library, which does not exist if Excel 97 is installed on the machine.

To fix the macro, add the line "Activeworkbook.Sheets.Add" twice, to ensure that there are 5 worksheets in the workbook, and change the constant value from Excel.Application.5 to Excel.Application.

AdjustDates The Microsoft Project 4.0 and 95 versions of this macro are not supported because in Microsoft Project 98 the methods DateAdd and DateDifference require qualification. Microsoft Project 98 ships with a compatible version of this macro; however, to update the old macro, simply prepend DateAdd and DateDifference with Application.
DateRangeFromToday Microsoft Project 98 does not support this macro. This macro employs the unsupported behavior described above with regard to the AdjustDates macro.
EffortDriven This macro is made obsolete by the new scheduling engine, which supports Effort Driven tasks.

Microsoft Project 98 does not support this macro. Microsoft Project 98 VBA requires that you specify a property or method for all collection objects (e.g., Windows, Tasks). This is not the case for earlier versions of Microsoft Project VBA. For example, if you write ActiveProject.Tasks in Microsoft Project 95 VBA it returns the count of tasks. The EffortDriven macro employs this unsupported behavior.

To fix this macro, append .Count to all such statements.

RollupFormatting Microsoft Project 98 does not support this macro. This macro employs the unsupported behavior described above with regard to the EffortDriven macro.
TaskUpdate Microsoft Project 98 does not support this macro. This macro employs the unsupported behavior described above with regard to the EffortDriven macro.
Module Editor In Microsoft Project 98 VBA, the Module Editor has been replaced with the new Visual Basic Editor, which is common to all Microsoft Office applications. Microsoft Project 98 does not support macro code relating to the Module Editor. The Visual Basic Editor has its own object model and can be used in lieu of ViewApply "Module Editor".

Microsoft Project 3.0 Macros

Microsoft Project 98 does not support Microsoft Project 3.0 macros directly. In addition to having 3.0 macros in a Microsoft Project 3.0 project, it is possible that a Microsoft Project 4.0 or 95 project contains a Microsoft Project 3.0 macro stream. These versions of Microsoft Project leave Microsoft Project 3.0 macros intact when reading a 3.0 file. Only after the 3.0 macro is edited in Microsoft Project 4.0 or 95 is it converted to the Microsoft Project 4.0 or 95 VBA format.

If you open a Microsoft Project 4.0 or 95 file that contains a 3.0 macro stream in Microsoft Project 98, that macro is ignored and therefore is not visible in the Microsoft Project 98 list of available macros. To access this macro in Microsoft Project 98, you must first modify the macro in Microsoft Project 4.0 or 95 and convert it to the Microsoft Project 4.0 or 95 VBA format, which Microsoft Project 98 can read.

Macros Created with Localized Versions

VBA for Microsoft Project 98 is English only. Before you can use macros created with localized versions of VBA for Microsoft Project 4.0 and 95 in Microsoft Project 98, they must be delocalized, or translated into the English-only VBA employed by Microsoft Project 98. If you open a project containing macros created with a foreign language version of Microsoft Project 4.0 or 95 in Microsoft Project 98, the program will attempt to translate localized items to the latest version of VBA.

The following table lists the files required for translation and the folders where they should reside. If these libraries are located in the correct folders when the Microsoft Project 4.0 or 95 project is opened, Microsoft Project 98 will perform delocalization automatically. When loading a macro written in a localized version of VBA, the error message "Error Loading DLL" typically indicates that one or more of the necessary files was not found.


Language of macros
System folder (Windows 95) or System32 folder (Windows NT)
Folder containing Winproj.exe
Danish VBADa32.dll, VBAEn32.olb Pj4Da32.olb, Pj4En32.olb
French VBAFr.32.dll, VBAEn32.olb Pj4Fr32.olb, Pj4En32.olb
German VBADe32.dll, VBAEn32.olb Pj4De32.olb, Pj4En32.olb
Italian VBAIt32.dll, VBAEn32.olb Pj4It32.olb, Pj4En32.olb
Japanese VBAJp32.dll, VBAEnD32.olb Pj4Jp32.olb, Pj4End32.olb
Norwegian VBANo32.dll, VBAEn32.olb Pj4No32.olb, Pj4En32.olb
Spanish VBAEs32.dll, VBAEn32.olb Pj4Es32.olb, Pj4En32.olb
Swedish VBASv32.dll, VBAEn32.olb Pj4Sv32.olb, Pj4En32.olb
Traditional Chinese VBAChT32.dll, VBAEnD32.olb Pj4ChT32.olb, Pj4End32.olb

While every item in the Object Library for Microsoft Project and all VBA language keywords have been delocalized to English, in isolated cases translation may not be 100 percent accurate. In those cases, you will need to modify the object model components of the module manually.

In addition, Microsoft Project 98 will attempt to delocalize code associated with toolbar buttons; however, in certain cases delocalization will fail, and you will need to modify the command manually (for example, when a single button includes two commands separated by a colon).

Strings, module names, and macro names have not been delocalized and should work without translation.

Password-protected Modules

Unlike earlier versions, Microsoft Project 98 supports passwords for projects, but not individual modules. When you open older projects containing protected modules, Microsoft Project 98 prompts you for the password for each protected module. If the correct password is entered, the module is unhidden and will be saved when you save the converted project. (You are given as many opportunities as necessary to supply the correct password.) The password is required each time you open the converted project in Microsoft Project 98 until you save it.

If any modules are skipped, Microsoft Project 98 attempts to save them in a new, protected project with an unspecified password. (The project will be named "FileNameMacros", where FileName is the name of the project originally containing the hidden modules.) Macro code in those modules will still run, provided it is compatible with Microsoft Project 98 VBA, but you cannot view, edit, or record macros in that project. If for any reason Microsoft Project 98 is unable to create the protected project, you are given the opportunity to name and save it manually.

If hidden modules are saved in the protected "FileNameMacros" project, but the converted project is not saved, the correct password is required for the protected modules contained within it each time the original project is opened in Microsoft Project 98 until it is converted and saved. Since the "FileNameMacros" project already exists, Microsoft Project is not able to save the hidden modules to a project with that name. You will need to overwrite the existing "FileNameMacros" project or give it a new name.

If you save the protected "FileNameMacros" project, a reference to it is added to the converted project that opens it each time the converted project is opened. This enables you to access and use the protected macros. If you are asked for the name of a project in which to store the hidden macros, but do not enter a project name, and the converted project is saved anyway, a reference is not made. In this case, you must specify a reference to that location manually.

If other (nonhidden) macros or toolbar buttons contain references to macros in formerly hidden modules, they must be changed manually. The reference should be "FileNameMacros!MacroName", where FileName is the name of the project originally containing the hidden module (or the user-supplied replacement to "FileNameMacros") and MacroName is the name of the macro in the formerly hidden module.

Changes to Microsoft Project 98 VBA

The following sections and tables describe changes to the Microsoft Project 98 VBA object model.

New Objects, Properties, and Methods

Objects that have been added to Microsoft Project 98 VBA are listed in the following table. Properties and methods that have been added to existing objects, or are associated with objects new to Microsoft Project 98, are listed in the VBA Object Browser or VBA Help.

Object Description
CostRateTable, CostRateTables New multiple pay rate functionality
PayRate, PayRates New resource rate table functionality
SplitPart, SplitParts New split task functionality
TimeScaleValue, TimeScaleValues New timescale data functionality

Hidden Properties and Methods

Many of the properties and methods that have been replaced by new functionality in Microsoft Project 98 have been hidden rather than removed. These properties and methods are supported only for backward compatibility; for new code, you should use the replacement functionality provided in Microsoft Project 98. Hidden properties and methods for visible objects are listed in VBA Help.

Changed Properties and Methods

Properties and methods that have been changed for Microsoft Project 98 are listed in the following table. Also listed are any constants, properties, or methods that have been removed. Any code that uses these items may produce errors and should be modified accordingly.

Item Object Change
ConsolidateProjects method Application The meaning of NewWindow has changed and PoolResources is ignored.
CreateMSGraph method Application Removed.
FilterEdit method Application Inserted Parenthesis into argument list.
HelpMicrosoftNetwork method Application Removed.
HelpKeywordHelp method Application Removed.
OptionsView method Application The DisplayNotesIndicator argument was removed.
EditCopy method Application All arguments have been removed.
EditUndo method Application Removed.
EditCopyPicture method Application The ForPrinter argument has changed from Boolean to Long.
EnableCancelKey property Application Changed from Boolean to Long.
FilePageSetupFooter method Application All arguments have been removed.
FilePageSetupFooterText method Application Removed.
FilePageSetupHeader method Application All arguments have been removed.
FilePageSetupHeaderText method Application Removed.
FilePageSetupLegend method Application The Left, Center, and Right arguments have been removed.
FilePageSetupLegendText method Application Removed.
LevelingOptions method Application The RemoveDelay argument has been removed.
OptionsModuleFormat method Application Removed.
OptionsModuleGeneral method Application Removed.
OptionsSchedule method Application The FixedDuration argument (Boolean) has been replaced with TaskType (Long).
OptionsSpelling method Application The ProjectComments argument has been replaced with AssignNotes.
pjCustomizeToolbars constant PjDialog Removed.
pjDB3 constant PjFileFormat Removed.
pjDB4 constant PjFileFormat Removed.
pjFOX constant PjFileFormat Removed.
pjModuleEditor constant PjViewScreen Removed.
pjMPX1 constant PjFileFormat Removed.
pjMPX3 constant PjFileFormat Removed.
pjWK1 constant PjFileFormat Removed.
pjWK3 constant PjFileFormat Removed.
pjWKS constant PjFileFormat Removed.
pjUsageProjectFinish constant PjGridline Removed.
pjUsageProjectStart constant PjGridline Removed.
ProjectID property Assignment Removed.
StartWeekOn property Application Changed from Boolean to Long.
WindowActivate method Application No longer activates the Customize Toolbars dialog box.

Miscellaneous Changes

Extensive changes have been made to the Microsoft Project 98 VBA object model to support new and improved features in the application. Existing macro code may result in errors or other unexpected behavior if it is not adapted to reflect these changes.

Change Description
Using Tasks.Index and Tasks.Count in consolidated projects Returns only those tasks that appear in the master project. To return every task in every subproject, use a For Each … In … Tasks construct.
Using the Count property with ActiveSelection.Resources and ActiveSelection.Tasks Includes blank rows in its result. Referencing one of these blank rows returns a Null task in a task view or a Null resource in a resource view.
OutlineParent property When used at the top level of a project, now returns a Task object rather than a Project object.
Qualification The Top, Width, and Height properties and the DateAdd and DateDifference methods must now be qualified with Application.

New Features of Microsoft Project 98 VBA

The major feature changes made for VBA in Microsoft Project 98 are listed below and are discussed in detail in the following sections.

Events

Microsoft Project 98 VBA incorporates a new event-handling model that is common to all Microsoft Office applications. Similar to the event-handling model used by Visual Basic, this event-handling model enables the programmer to write code that is run when some action takes place. In Microsoft Project 98, event procedures can be initiated at the application or project level.

Microsoft Project object events

Microsoft Project events occur when the project changes in some way. The following table describes event procedures available at the project level:

Event Name Occurs
Activate when switching to the project from another project
BeforeClose before the project closes
BeforePrint before the project is printed or previewed
BeforeSave before the project is saved
Calculate after the project is calculated
Change when a change is made to data in the project
Deactivate when switching from the project to another project
Open when the project opens, but before the Activate event

Application object events

Application events occur when a project is created. To write event procedures for the Application object, you must create a new class module and declare the object of type Application with events. New application objects appear in the Object drop-down list box in the class module.

The NewProject event is a predefined Application object event that occurs when a new project is created and is analogous to the Microsoft Project object Open event described above.

UserForms

The new UserForm object enables you to add custom windows and dialog boxes to an application's user interface. Because UserForm is an Object data type, you can declare variables as type UserForm before setting them to an instance of a type of UserForm declared at design time. Similarly, you can pass an argument to a procedure as type UserForm, and you can create multiple instances of UserForms in code. UserForms can respond to events initiated by a user or triggered by the system. For example, you can write code in a UserForm's Initialize event procedure to initialize module-level variables before the UserForm is displayed. You can also use methods to manipulate UserForms in code.

ActiveX Controls

Support for ActiveX controls in the Microsoft Project 98 VBA expands the number and type of controls available and allows you to use controls common to the other Microsoft Office applications in your Microsoft Project 98 Visual Basic applications. In addition, you can write custom ActiveX controls or incorporate custom controls from third-party vendors.

CommandBars

The Microsoft Project 98 VBA adds programmatic support for Microsoft Office toolbars, menu bars, and shortcut menus as CommandBar objects. You can modify any built-in menu bar or toolbar, and you can create and modify custom toolbars, menu bars, and shortcut menus that are a part of your Visual Basic application. Your application features are presented as individual buttons on toolbars or as groups of command names on menus. Because toolbars and menus are both command bars, they use the same kind of controls.

The built-in command bar controls in container applications are also represented in Visual Basic by CommandBar objects. You can modify the location and appearance of built-in controls, or you can assign a custom macro to any built-in control to completely replace its built-in behavior.

The information contained in this document represents the current view of Microsoft Corporation on the issues discussed as of the date of publication. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information presented after the date of publication.

This document is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS DOCUMENT.