Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: How to Implement Automation to Microsoft Project


View products that this article applies to.

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.

↑ Back to the top


Summary

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

↑ Back to the top


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.

↑ Back to the top


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.

↑ Back to the top


Keywords: KB210014, kbinterop, kbhowto

↑ Back to the top

Article Info
Article ID : 210014
Revision : 3
Created on : 1/23/2007
Published on : 1/23/2007
Exists online : False
Views : 282