Using the Project.Open Event

Switch View :
ScriptFree
Using the Project.Open Event

Microsoft Office Project 2007 no longer supports the AutoOpen macro. Instead, you can use the Project.Open event. Different Project_Open event handlers can run, depending on whether you are connected to Microsoft Office Project Server 2007.

In the Visual Basic Editor, expand all of the nodes in the left pane to see the location of the ThisProject object in each project. You can put different Project_Open event handlers in ThisProject objects in each of the following nodes.

  • VBAProject (Project name.mpp) You can save a Project_Open event handler in each project that runs when you open the project. You can be connected to Project Server or not, and the project can be stored on the local computer, on a file share, in a Shared Documents library in Windows SharePoint Services, or in Project Server.

  • ProjectGlobal (Global.MPT) The Project_Open event handler in the global template runs only when you are not connected to Project Server and when you open any project stored on the local computer, on a file share, or in a Shared Documents library in Windows SharePoint Services. The following code example displays a message on when Project starts up, and a different message when you open a project.

    Visual Basic
    Sub Project_Open(ByVal pj As Project)
        If (pj Is Nothing) Then
            MsgBox "Called Project_Open from Global.MPT."
        Else
            MsgBox "Global.MPT: Opened project: " & pj.Name
        End If
    End Sub
    
  • VBAProject (Global (+ non-cached Enterprise)) The Project_Open event handler in the enterprise project template runs only when you are connected to Project Server and when you open any project. The project can be local, on a file share, in a Shared Documents library in Windows SharePoint Services, or opened from Project Server. The following code is similar to the previous example, but displays different messages from the enterprise global template.

    Visual Basic
    Sub Project_Open(ByVal pj As Project)
        If (pj Is Nothing) Then
            MsgBox "Called Project_Open from EGlobal."
        Else
            MsgBox "EGlobal: Opened project: " & pj.Name
        End If
    End Sub
    

See Also