ACC: How to Use Automation with Microsoft Project

Last reviewed: August 28, 1997
Article ID: Q154787
The information in this article applies to:
  • Microsoft Access versions 7.0, 97
  • Microsoft Project for Windows 95, version 4.1a

SUMMARY

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

This article demonstrates 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.

  1. Open the sample database Northwind.mdb and create a new module.

  2. On the Tools menu, click References.

  3. 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.

  4. Click OK.

  5. 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
    
    

  6. To test this function, type the following line in the Debug window, and then press ENTER.

          ?ProjectOLE()
    

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.

REFERENCES

For more information about working with other applications using Automation, search the Help Index for "Working across Applications," or ask the Microsoft Access 97 Office Assistant.

Keywords          : AutoGnrl kbinterop IntpOleA
Technology        : kbole
Version           : 7.0 97
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbhowto


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 28, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.