Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ProjectBeforeClearBaseline Event Example for Microsoft Project 2002

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.
 

Randall Isenhour
Microsoft Corporation

August 2002

Contents

Overview
Requirements
Running the code example
Use events to confirm changes in your project's baseline plan
ProjectBeforeClearBaseline event sample code

Overview

The following sample displays a message box informing the user of a baseline clearing about to be made in the project plan. The message box indicates which baseline is being cleared (from 0 to 10), the file name of the project, and whether the interim plan is being cleared (True or False). (3 pages)

Requirements

  • Microsoft® Project Professional 2002 or Microsoft Project Standard 2002

Running the code example

This code example assumes that you are familiar with Microsoft Project and Microsoft Visual Basic® for Applications (VBA), and that you can write or reuse supplementary code as necessary.

To run this code example, you must have Microsoft Project 2002 (either Standard or Professional edition) installed on your computer. You can either paste the code into the Microsoft Visual Basic Editor (VBE) in Microsoft Project or into your VBA project.

Use events to confirm changes in your project's baseline plan

You can copy and paste the VBA code below into the appropriate Class Module and Module, as specified in the following procedure.

To create the VBA event code

  1. On the Tools menu, point to Macro and click Visual Basic Editor.
    Alternatively, press ALT + F11.
  2. In the Project Explorer window, select ProjectGlobal (Global.MPT).
  3. On the Insert menu, click Class Module.
    You can rename the Class Module in the (Name) field of the Properties window.
  4. Copy and paste the following code into the new Class Module:
    Public WithEvents pApp As MSProject.Application
    Private Sub pApp_ProjectBeforeClearBaseline(ByVal pj As Project, _
       ByVal Interim As Boolean, ByVal bl As PjBaselines, _
       ByVal InterimFrom As PjSaveBaselineTo, _
       ByVal AllTasks As Boolean, ByVal Info As EventInfo)
        
       MsgBox "Click OK to clear the baseline for the following " _
          & "project:" & vbCrLf & "Baseline: " & CStr(bl) _
          & vbCrLf & "Project: " & pj.Name & vbCrLf _
          & "Clear interim plan: " & CStr(Interim)
    End Sub
    
    
  5. On the Insert menu, click Module.
    You can rename the Module in the (Name) field of the Properties window.
  6. Copy and paste the following code into the new Module.
    Public X As New Class1
    Sub EnableEvents()
        Set X.pApp = MSProject.Application
    End Sub
    
  7. On the Run menu, click Run Sub/UserForm.
  8. In the Macros box, select EnableEvents and click Run.
    At this point, Microsoft Project has initialized a Microsoft Project Application object and is listening for the ProjectBeforeClearBaseline event.

To test the VBA event code

  1. If you have not already done so, save a baseline plan in your project.
    On the Tools menu, point to Tracking and click Save Baseline.
  2. On the Tools menu, point to Tracking and click Clear Baseline.
    The ProjectBeforeClearBaseline event occurs and Microsoft Project displays the message box with information about the baseline being cleared.

ProjectBeforeClearBaseline event sample code

Class Module code

Public WithEvents pApp As MSProject.Application
Private Sub pApp_ProjectBeforeClearBaseline(ByVal pj As Project, _
   ByVal Interim As Boolean, ByVal bl As PjBaselines, _
   ByVal InterimFrom As PjSaveBaselineTo, _
   ByVal AllTasks As Boolean, ByVal Info As EventInfo)
    
   MsgBox "Click OK to clear the baseline for the following " _
      & "project:" & vbCrLf & "Baseline: " & CStr(bl) _
      & vbCrLf & "Project: " & pj.Name & vbCrLf _
      & "Clear interim plan: " & CStr(Interim)
End Sub

Module code

Public X As New Class1
Sub RunMacros()
   Set X.pApp = MSProject.Application
End Sub

Show:
© 2014 Microsoft