ACC: How to Use Automation with Microsoft Project

ID: Q154787

The information in this article applies to:

SUMMARY

Advanced: Requires expert coding, interoperability, and multiuser skills.

This article shows you how to use Automation to manipulate a Microsoft Project for Windows 95, version 4.1a (*.mpp) file.

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.

MORE INFORMATION

The following sample procedure opens an existing Microsoft Project 4.1a file to perform these actions:

This example assumes you have the sample file, Pert.mpp, installed in a folder (directory) called C:\Msoffice\Winproj\Library.

1. Open the sample database Northwind.mdb and create a new module.

2. On the Tools menu, click References.

3. Click to select the Project 4.1 Object Library check box. If the

   selection is not available, click Browse to locate the Pj4en32.olb
   file.

4. Click OK.

5. Create the following procedure in the open module:

      Function ProjectOLE()
         Dim ProjObj As MSProject.Application
         Set ProjObj = CreateObject("msproject.application")
         ProjObj.FileOpen "C:\Msoffice\Winproj\Library\Pert.mpp", _
            ReadOnly:=True
         ProjObj.Visible = True

         ' Run a macro.
         ProjObj.Macro "ToggleReadOnly" ' Toggle file back to read-write.

         ' Add tasks to the project.
         Dim i As Integer
         Dim ProjDoc As MSProject.Project
         Set ProjDoc = ProjObj.ActiveProject
         For i = 1 To 10
            ProjDoc.Tasks.Add Name:="Task" & i
         Next i

         ' Change font properties.
         ProjObj.SelectColumn
         ProjObj.FontItalic True

         ' Go to a specific cell in the column.
         ProjObj.EditGoTo 5, Date

         ' Print preview the file.
         ProjObj.FilePrintPreview
         'ProjObj.FilePrint   ' Use this line to print the file.
         'ProjObj.Filesave    ' Use this line to save the file.
         ProjObj.FileClose 0  ' 0=pjDoNotSave, 1=pjSave, 2=pjPromptSave.
         ProjObj.Quit
         Set ProjObj = Nothing
      End Function

6. To test this function, type the following line in the Debug window,
   and then press ENTER:

      ?ProjectOLE()

Microsoft Project opens, performs the specified actions, and displays a Print Preview window. Click Close in the Print Preview window. The sample function finishes, closing the Pert.mpp file and quitting Microsoft Project.

REFERENCES

For more information about using Automation to work with other applications, search the Help Index for "Working across Applications," or ask the Microsoft Access 97 Office Assistant.

Additionial query words:

Keywords          : kbinterop IntpOlea 
Version           : 7.0 97
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbhowto

Last Reviewed: November 21, 1998