VBA - MS Project - 使用 "Find" 后将单个任务分配给对象变量

VBA - MS Project - Assign single task to an Object variable after using "Find"

我需要以编程方式对一些任务进行更改。需要更改的任务在 Text10 字段中有 ID 号。我想尽可能避免使用过滤器,因为所有这些 ID 号都不同。由于项目文件有 10k+ 行,因此遍历所有任务花费的时间太长。我不确定“查找”是否是此处的正确方法。

问题:

有没有一种方法可以使用 Text10 找到任务并将其分配给“任务”对象,以便我随后可以对其进行操作? 以下内容无效,但希望能说明问题:

Sub test()

Dim t As Task

Set t = Find("Text10", "equals", "A1044Fh82")
t.SetField pjTaskDuration, 0


End Sub

谢谢!

Find method returns True if a matching value is found, and if so, the active selection is moved to the first matching task. So check the result of the Find method and then use the ActiveCell属性获取任务引用:

If Application.Find("Text10", "equals", "A1044Fh82") Then
    Dim t As Task
    Set t = Application.ActiveCell.Task
    t.Duration = 0
End If