You are currently offline, waiting for your internet to reconnect

How to programmatically start Microsoft Project Professional from an Office program by using the Shell function in a VBA macro

Support for Office 2003 has ended

Microsoft ended support for Office 2003 on April 8, 2014. This change has affected your software updates and security options. Learn what this means for you and how to stay protected.

This article describes how to programmatically start Microsoft Project Professional from a Microsoft Office program by using the Shell function in a Microsoft Visual Basic for Applications (VBA) macro.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

To programmatically start Microsoft Project Professional from an Office program by using the Shell function in a VBA macro, create a VBA macro that is similar to the following macro example.
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)Sub StartMSProject()Dim sServer As StringDim sServerUser As StringDim sServerPass As StringDim sServerString As StringDim sProjectName As StringDim t As LongDim p As ObjectDim b As BooleanOn Error Resume Next Set p = GetObject(, "MSProject.Application")' Determine whether Project is already running.If Not p Is Nothing Then   b = True   MsgBox "Microsoft Project is already running. It will now be shut down. Please restart the macro."End If'If Project is running, shut down Project. Then, you must restart this macro.If b Then   p.Quit   Exit SubEnd If 'logon parameters for Project ServersServer = "http://servername/projectserver" ' for example, http://server85/projectserversServerUser = "Username"' If the sServerPass password is blank, the user must click OK  ' when the server logon dialog box appears. Note that we do not recommend a blank password. A non-blank password will log the user on automatically without ' user interaction.sServerPass = "Userpassword"sServerString = "winproj.exe /s """ & sServer & """ /u """ & sServerUser & """ /p """ & sServerPass & """"' Replace projectname with the name of your project.sProjectName = "projectname" 'Start Project. If you want to start with a Windows logon, remove the /u and /p parameters'from the ServerStringShell sServerString 'At this point, fail to an error handler if the application object cannot be created.'This behavior occurs because the Shell function does not "wait" for the application to start; the code continues'to execute. Because Project may be busy logging on, the following Set statement may fail. This'artificial 'loop' gives Project time to finish the logon process.t = Timer + 15 ' get the current time + 15 secondsSleep 15000 'Wait 15 seconds to give Project to finish the logon process.On Error GoTo NotReady'get object to project for automationSet p = GetObject(, "Msproject.Application")On Error GoTo 0        p.FileOpen "<>\" & sProjectNamep.WindowActivate sProjectNameExit Sub NotReady:   If Timer > t Then      MsgBox "Microsoft Project has not been able to start for 15 seconds. Try again later."   Else       Resume   End IfEnd Sub
PRJ2007 project2003 prj2003 prj2k3 project2002 prj2002 prj2k2

Article ID: 895509 - Last Review: 09/18/2011 02:40:00 - Revision: 7.0

Microsoft Office Project Professional 2007, Microsoft Office Project Professional 2003, Microsoft Project 2002 Professional Edition, Microsoft Project Professional 2010, Microsoft Project Server 2010, Microsoft Project Standard 2010

  • kbprogramming kbautomation kbvba kbhowto KB895509