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

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

问题描述

我有一个 vbscript 来检查 MS Project 是否打开.如果它已经打开它运行一个宏如果没有它应该打开项目然后运行宏.如果项目已经打开,它工作正常.如果项目未打开,脚本会成功打开并运行宏,但中途失败.基本上它失败了,因为被调用的宏从项目服务器打开文件.即使我的默认帐户设置为项目服务器 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?

推荐答案

真正的问题是:

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

Basically it fails because the macro that is being called opens files from project server.

为了自动化 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.

注意:根据需要更新 sleep 值,以便在尝试获取对它的引用之前为 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 OfficeOffice14Winproj.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 "网址"
  • /u "用户名"
  • /p "密码"
  • 文件名
  • -项目配置文件

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

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