ACC2000: How to Implement Automation to Microsoft Project (210014)



The information in this article applies to:

  • Microsoft Project 2000
  • Microsoft Access 2000

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.
  1. Start Microsoft Project, and then click Save As on the File menu.
  2. In the Save in box, browse to the root directory of drive C, and then click Save to save the Project1.mpp file.
  3. Quit Microsoft Project, start Microsoft Access, and then open the sample database Northwind.mdb.
  4. Create a new module, and then click References on the Tools menu.
  5. 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.
  6. Click OK to close the References dialog box.
  7. 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
    					
  8. 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.
  9. Click Close in the Print Preview window. The sample function finishes running, closes the Project1.mpp file, and then closes Microsoft Project.

REFERENCES

For more information about how to use Automation with other programs, click Microsoft Visual Basic Help on the Help menu, type working across applications in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

Modification Type:MajorLast Reviewed:6/29/2004
Keywords:kbhowto kbinterop KB210014