0

在不同应用程序中的宏结束后,让使用 GetObject() 打开的 MS Project 文件打开并对用户可见的正确方法是什么?

我在网上找到的信息表明,在对象超出范围之前将Application.UserControl 属性设置为 True 应该允许用户继续使用打开的文件。但是,至少对于 MS Project,Application.UserControl 属性似乎是只读的。有没有办法解决这个问题?

显示问题的简化示例:

Sub AddTasks()
    Dim proj As Object

    ' Already have the file path from another part of the workflow
    Set proj = GetObject("C:\projtest.mpp")

    ' perform some calculations and add new tasks to project
    proj.Tasks.Add "additional task"

    ' Leave Project open and visible for the user
    proj.Application.Visible = True
    proj.Application.UserControl = True ' Gives "Type Mismatch" error
    ' without the UserControl line, runs ok, but Project closes after the end of the macro
End Sub
4

2 回答 2

1

您可以创建应用程序的实例并在实例中打开项目文件,而不是使用 GetObject?

Sub AddTasks()
   Dim msProj as Object
   Set msProj = CreateObject("Project.Application")

   msProj.FileOpen "C:\projtest.mpp"

   'do stuff to project file here

   msProj.Visible = True
End Sub

类似上面的东西(我无法测试上面的代码,因为我没有 MSProject,但类似的代码适用于 MSWord)

于 2010-10-06T12:36:16.527 回答
0

对于 Project UserControl 仅指示用户是否启动了应用程序;它似乎是只读的,因为它是。我还没有完成您对 Project 的要求,尽管这里有一个 Word 尝试查看和查找正在运行的 Excel 实例的类似示例。也许这有点帮助:

can-vba-reach-cross-instances-of-excel

于 2010-10-05T20:35:59.887 回答