【发布时间】:2020-07-01 07:07:01
【问题描述】:
我如何使用 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
【问题讨论】:
标签: vba ms-project