打开MS Project时连接到项目服务器 [英] Connect to a project server when opening MS Project

查看:256
本文介绍了打开MS Project时连接到项目服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个vbscript,用于检查MS Project是否已打开.如果已经打开,它将运行一个宏;如果尚未打开,则应打开Project,然后运行该宏.如果Project已经打开,则可以正常工作.如果未打开项目,则脚本会成功打开并运行宏,但会中途失败.基本上,它会失败,因为被调用的宏会打开项目服务器中的文件.即使将我的默认帐户设置为Project Server URL,并且在启动时"设置为选择我的默认帐户",它仍然会失败.

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打开&运行宏:

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 

在Project打开时是否有一种强制它连接到项目服务器站点的方法?

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

推荐答案

这是真正的问题:

基本上它失败了,因为正在调用的宏会打开项目服务器中的文件.

为了自动执行MS Project并将其打开到项目服务器,您需要使用如下命令行开关来启动winproj.exe:

In order to automate MS Project and have it open to a project server, you need to launch winproj.exe using a command-line switch as follows:

VBScript

On Error Resume Next
Dim pjApp 
Set pjApp = GetObject(, "MSProject.Application")
If Err.Number <> 0 Then
    Dim ProjServer
    ProjServer = Chr(34) & "enter project server name here" & Chr(34)
    Set objShell = WScript.CreateObject("WScript.Shell")
    objShell.Run "winproj /s " & ProjServer, 1, True
    Set objShell = Nothing 
    WScript.Sleep 5000
    Set pjApp = GetObject(, "MSProject.Application")
End If
pjApp.Macro "testsave"

代码首先检查MS Project是否已经打开,如果已经打开,则使用该实例.否则,它将使用shell命令打开特定的项目服务器.

The code first checks to see if MS Project is already open and if so, uses that instance. Otherwise it uses the shell command to open to a specific project server.

注意:如有必要,请更新睡眠值,以使MS Project有足够的时间打开,然后再尝试获取对其的引用.

Note: Update sleep value as necessary to give MS Project enough time to open before trying to get a reference to it.

VBA版本

On Error Resume Next
Dim pjApp As MSProject.Application
Set pjApp = GetObject(, "MSProject.Application")
If Err.Number <> 0 Then
    Dim ProjServer As String
    ProjServer = Chr$(34) & "enter project server name here" & Chr$(34)
    Shell "C:\Program Files (x86)\Microsoft Office\Office14\Winproj.exe /s " & ProjServer, vbNormalFocus
    Do While pjApp Is Nothing
        DoEvents
        Set pjApp = GetObject(, "MSProject.Application")
    Loop
End If
pjApp.Macro "testsave"

注意:根据需要更新Winproj.exe的路径.

Note: Update the path to Winproj.exe as necessary.

命令行开关的文档似乎已从Microsoft的站点中删除.这是一个仍提供文档的页面: 为项目使用命令行开关.简要地:

Documentation for command-line switches seems to have been removed from Microsoft's site. Here's a page that still provides the documentation: Using Command-line switches for Project. Briefly:

  • /s"URL"
  • /u用户名"
  • /p密码"
  • 文件名
  • -ProjectProfiles

这篇关于打开MS Project时连接到项目服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆