Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 154787 - Last Review: January 19, 2007 - Revision: 3.3
ACC: How to Use Automation with Microsoft Project
This article was previously published under Q154787
Advanced: Requires expert coding, interoperability, and multiuser skills.
SUMMARY
This article shows you 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.
- Open the sample database Northwind.mdb and create a new module.
- On the Tools menu, click References.
- 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.
- Click OK.
- 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
- 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 using Automation to work with other
applications, search the Help Index for "Working across Applications,"
or ask the Microsoft Access 97 Office Assistant.
Additionial query words:
APPLIES TO
- Microsoft Access 95 Standard Edition
- Microsoft Access 97 Standard Edition
- Microsoft Project 4.1a
| kbhowto kbinterop kbprogramming KB154787 |
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
Be the first to leave feedback, to help others about this knowledge base
article.
(Optional) Name
(Optional)
Public URL Or Email
Comments
No
HTML -- Text Only Please