Command line switches in VBA?

P

Pete

From a command line I can use switches to specify the Project Server,
Username, Password, and a few other things.

e.g.

WINPROJ.EXE /s "http://Server/ProjectServer /u "MyUserName" /p "MyPassword"

In VBA (say from an Excel macro) I open an instance of Project via:

Dim pj as New MSProject.Application

But there are no options provided here to specify all the information above.

Is there another (perhaps better) way to open an instance of Project from
another Office application so that I can specify the Project Server info?

Thanks for your help!

-Pete
 
P

Pete

Clarification: I'd like to open Project AND store a reference to it in a
local variable to work with later.

I've tried using Shell, but the code doesn't wait for Shell to finish, so I
can't get a reliable reference to the Project Application object. Maybe
there's a good way to detect that there is an instance of Project open? Then
I could open Project with Shell, and loop until it's finished opening before
the code continues?

-Pete
 
R

Rod Gill

Hi,

If you have a reference to Project, then use:

Dim projApp as MSProject.Application
on error resume next
set projApp=GetObject(,"MSProject.Application") 'Existing instance
running?
if not projApp is nothing then
Set projApp=CreateObject("MSProject.Application") 'Create new
instance
projapp.visible=true
End If

--

Rod Gill
Project MVP

Project VBA Book, for details visit:
http://www.projectvbabook.com

NEW!! Web based VBA training course delivered by me. For details visit:
http://projectservertraining.com/learning/index.aspx
 
P

Pete

Thanks for your help Rod. Here's what I ended up using:

Public Function GetProjectApp() As MSProject.Application
On Error Resume Next
Shell "WINPROJ.EXE /s ""http://server/projectserver"" /u ""MyUserName""
/p ""MyPassword"""
While GetProjectApp Is Nothing
Set GetProjectApp = GetObject(, "MSProject.Application")
Wend
End Function


The code just keeps on running after the Shell method is fired, so the
GetObject method fails for the first 2000 tries or so. Once Project finishes
establishing the server connection and opens up then the GetObject method
finds the open instance and returns it.

Thanks again for your help. Please let me know if you see any major flaws
with using this technique, or if you have any ideas for improvement.

-Pete
 
J

John

Pete said:
Thanks for your help Rod. Here's what I ended up using:

Public Function GetProjectApp() As MSProject.Application
On Error Resume Next
Shell "WINPROJ.EXE /s ""http://server/projectserver"" /u ""MyUserName""
/p ""MyPassword"""
While GetProjectApp Is Nothing
Set GetProjectApp = GetObject(, "MSProject.Application")
Wend
End Function


The code just keeps on running after the Shell method is fired, so the
GetObject method fails for the first 2000 tries or so. Once Project finishes
establishing the server connection and opens up then the GetObject method
finds the open instance and returns it.

Thanks again for your help. Please let me know if you see any major flaws
with using this technique, or if you have any ideas for improvement.

-Pete

Pete,
Pardon me for jumping in, but I do have a comment. Letting a procedure
run until something happens probably isn't a good idea. What if Project
never opens? If you don't have some built-in time out as a fail safe,
the procedure will just keep running and eventually crash the PC.

John
Project MVP
 
P

Pete

John,

Thanks for jumping in! I agree. A timeout feature would be a good
addition. Do you have any suggestions for a good way to implement it, or
perhaps a better way to open Project so that it logs onto Project Server
instead of defaulting to the local computer profile?

Thanks again,

-Pete
 
R

Rod Gill

Hi,

Project is a single instance app, so if Project is already running, you are
going to get unpredictable results. You should use GetObject to connect to
any existing instance, then GetProjectServerVersion or ConnectionState to
determine if connected to PS. Yes you need to use shell to start Project
connected to Project Server.

Leave out the /u and /p parameters and Project should login to PS using NT
authentication.

--

Rod Gill
Project MVP

Project VBA Book, for details visit:
http://www.projectvbabook.com

NEW!! Web based VBA training course delivered by me. For details visit:
http://projectservertraining.com/learning/index.aspx
 
J

John

Pete said:
John,

Thanks for jumping in! I agree. A timeout feature would be a good
addition. Do you have any suggestions for a good way to implement it, or
perhaps a better way to open Project so that it logs onto Project Server
instead of defaulting to the local computer profile?

Thanks again,

-Pete

Pete,
I'm not a Project Server MVP so I can't really help you with that.

With regard to the timeout, it could be implemented by a counter in the
loop that allows a certain number of tries, or an actual timer that uses
the Timer function.

John
Project MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top