我正在尝试快速找到以只读方式打开MS Project文件的方法,最好是从资源管理器中打开。我跟着教程负责人使用this tutorial使用以下代码从excel做同样的事情:
'-------------------- Open as Read-Only.vbs --------------------
Option Explicit
Dim app 'As Object
Call OpenAsReadOnly
Sub OpenAsReadOnly()
On Error Resume Next
Set app = GetObject(, "Excel.Application")
If IsEmpty(app) Then Set app = CreateObject("Excel.Application")
With app.Workbooks.Open(WScript.Arguments(0))
If Not .ReadOnly Then .ChangeFileAccess 3 'xlReadOnly
app.Visible = True
End With
End Sub
但是当我尝试像这样修改项目时:
'-------------------- Open as Read-Only.vbs --------------------
Option Explicit
Dim app 'As Object
Call OpenAsReadOnly
Sub OpenAsReadOnly()
On Error Resume Next
Set app = GetObject(, "MSProject.Application")
If IsEmpty(app) Then Set app = CreateObject("MSProject.Application")
With app.Project.Open(WScript.Arguments(0))
If Not .ReadOnly Then .ChangeFileAccess 3 'xlReadOnly
app.Visible = True
End With
End Sub
MS Project闪烁然后关闭。有什么想法吗?
答案 0 :(得分:0)
打开MS Project文件的方法是app.FileOpenEx
。第一个参数是文件名,第二个参数是ReadOnly选项。 MS Project中没有ChangeFileAccess
方法。
请改为尝试:
Dim app
Set app = GetObject(, "MSProject.Application")
If IsEmpty(app) Then Set app = CreateObject("MSProject.Application")
app.FileOpenEx(WScript.Arguments(0), True)