如何使用 ms project-vba 搜索多个任务名称?

How I can search multiple task names using ms project-vba?

如何使用 MS-Project VBA 搜索多个任务名称,因为我已将多个任务名称复制到剪贴板并通过拆分分成数组项。

这段代码我一次搜索一个任务,给出任务 ID 和任务名称。我想做的是一次查找多个任务ID。

我只想在 ActiveProject.Tasks 中搜索整个数组 x() 以找到匹配项。

Sub NameExample()
Dim t As Task
Dim x() As String
Dim y As String
Dim p As Variant
Dim q As String

Dim MyData As DataObject
Dim strClip As String

Set MyData = New DataObject
MyData.GetFromClipboard
p = MyData.GetText
x = Split(p, vbCrLf)



    For Each t In ActiveProject.Tasks
        If InStr(1, t.Name, x(0), 1) Then
           y = y & vbCrLf & t.ID & ": " & t.Name
        End If
    Next t

    If Len(y) = 0 Then
        MsgBox "No tasks with the text "
    Else
        MsgBox y


   End If

End Sub

解决了!

Sub NameExample()
Dim t As Task
Dim x() As String 
Dim p As String
Dim q As Variant

Dim MyData As DataObject
Dim strClip As String

Set MyData = New DataObject
MyData.GetFromClipboard
p = MyData.GetText
x = Split(p, vbCrLf)

For Each q In x
    For Each t In ActiveProject.Tasks
        If InStr(1, t.Name, q, 1) Then
            y = y & vbCrLf & t.ID & ": " & t.Name
        End If
    Next t
Next q

    If Len(y) = 0 Then
        MsgBox "No tasks with the text "
    Else
        MsgBox y
    End If

End Sub