【问题标题】:How I can search multiple task names using ms project-vba?如何使用 ms project-vba 搜索多个任务名称?
【发布时间】: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


    【解决方案1】:

    解决了!

    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
    

    【讨论】:

      猜你喜欢
      • 2015-10-28
      • 1970-01-01
      • 2016-10-01
      • 2022-07-07
      • 1970-01-01
      • 2016-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多