Microsoft Knowledge Base Email Alertz

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

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 210014 - Last Review: January 23, 2007 - Revision: 2.1

ACC2000: How to Implement Automation to Microsoft Project

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.

APPLIES TO
  • Microsoft Project 2000 Standard Edition
  • Microsoft Access 2000 Standard Edition
Keywords: 
kbhowto kbinterop KB210014
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate