Microsoft KB Archive/210014

= ACC2000: How to Implement Automation to Microsoft Project =

Article ID: 210014

Article Last Modified on 1/23/2007

-

APPLIES TO


 * Microsoft Project 2000 Standard Edition
 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q210014



This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

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



SUMMARY
This article shows you how to use Automation code to manipulate a Microsoft Project (*.mpp) file from Microsoft Access.



MORE INFORMATION
The sample function provided in this article opens an existing Microsoft Project file, and then performs the following actions:
 * Runs a Microsoft Project macro.
 * Adds tasks to the project.
 * Changes font properties in a column.
 * Moves to a specific cell in the project.
 * Displays a print preview of the project.
 * Closes the Microsoft Project file and program.

 Start Microsoft Project, and then click Save As on the File menu. In the Save in box, browse to the root directory of drive C, and then click Save to save the Project1.mpp file. Quit Microsoft Project, start Microsoft Access, and then open the sample database Northwind.mdb. Create a new module, and then click References on the Tools menu. In the Available References list, click to select the Microsoft Project 9.0 Object Library check box. If the Microsoft Project 9.0 Object Library is not listed, click Browse to locate the Msprj9.olb file, which is in the folder where you have Microsoft Project installed. The default location is C:\Program Files\Microsoft Office\Office. Click OK to close the References dialog box.</li>  Create the following procedure in the open module: Option Compare Database Option Explicit

Function fncProjectOLE Dim prjApp As MSProject.Application Dim prjProject As MSProject.Project Dim intTask As Integer

Set prjApp = CreateObject("Msproject.Application")

prjApp.FileOpen "C:\Project1.mpp", ReadOnly:=True prjApp.Visible = True

'Run a macro. prjApp.Macro "Toggle_Read_Only" 'Toggle file back to read-write.

Set prjProject = prjApp.ActiveProject

'Add tasks to the project. For intTask = 1 To 10 prjProject.Tasks.Add Name:="Task" & intTask Next intTask prjApp.SelectColumn prjApp.FontItalic True 'Change font properties. prjApp.EditGoTo 5, Date 'Go to a specific cell in the column. prjApp.FilePrintPreview 'Print preview the file. 'prjApp.FilePrint      'Use this line to print the file. 'prjApp.FileSave       'Use this line to save the file. prjApp.FileClose pjDoNotSave prjApp.Quit

Set prjProject = Nothing Set prjApp = Nothing End Function </li>  To test this function, type the following line in the Immediate Window, and then press ENTER: ?fncProjectOLE Note that Microsoft Project opens, performs the specified actions, and then displays a Print Preview window. </li> Click Close in the Print Preview window. The sample function finishes running, closes the Project1.mpp file, and then closes Microsoft Project.</li></ol>

<div class="references_section">