Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
537 views
in Technique[技术] by (71.8m points)

macros - Connect to a project server when opening MS Project

I have a vbscript that checks to see if MS Project is open. If it's already open it runs a macro if not it should open Project then run the macro. It works fine if Project is already open. If project isn't open the script successfully opens and runs the macro but fails half way through. Basically it fails because the macro that is being called opens files from project server. even with my default account set to the Project server url and 'when starting' set to 'choose my default account' it still fails.

vbscript to open & run macro:

dim pjApp

on error resume next
set pjApp = GetObject(, "MSProject.Application")

    if err.Number = 0 then
    pjApp.Visible = True    
    pjApp.macro "testsave"
    else 
    Set pjApp = CreateObject("MSProject.Application") 
    pjApp.Visible = True 
    pjApp.macro "testsave"
    end if
Set pjApp = Nothing 

Is there a way of forcing it to connect to the project server site when Project opens?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In place of pjApp.macro try:

pjApp.Appllication.Run "testsave"

I know that it is weird that the .macro version works for the code above it; however, it is still worth a shot. This code should also work for both places where you are using the .macro method.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...