Microsoft KB Archive/154787

= ACC: How to Use Automation with Microsoft Project =

Article ID: 154787

Article Last Modified on 1/19/2007

-

APPLIES TO


 * Microsoft Access 95 Standard Edition
 * Microsoft Access 97 Standard Edition
 * Microsoft Project 4.1a

-



This article was previously published under Q154787



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



SUMMARY
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:
 * Run a macro
 * Add tasks to the project
 * Change font properties in a column
 * Move to a specific cell in the project
 * Display a print preview of the project
 * Close the Microsoft Project file and application

This example assumes you have the sample file, Pert.mpp, installed in a folder (directory) called C:\Msoffice\Winproj\Library.  Open the sample database Northwind.mdb and create a new module. On the Tools menu, click References. 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. Click OK.  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  To test this function, type the following line in the Debug window, and then press ENTER:

?ProjectOLE

</li></ol>

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.

<div class="references_section">