How to Set Flag field to Yes or No Based on Text input - Microsoft-Project-VBA

若如初见. 提交于 2020-01-15 08:28:07

问题


I am trying to automate creating flag field based on if text is in the task description. The goal is to use text to search through the project file and for each row with the text, in a flag field to put yes beside it.

I am able to generate a list of the activites in MS project with the Row IDs.

I am not sure how to use this list to generate "yes No" in Flag field

Sub Findtask()
Dim sTask As Task 'Summary level Task'
Dim aTask As Task 'Job level Task'
Dim Proj As Project 

x = InputBox$("Search for tasks that include the following text in their names:") 
Set Proj = ActiveProject
'Search for tasks tat include the following text in their names:"'
If Not x = "" Then
    For Each aTask In Proj.Tasks
    If InStr(1, aTask.Name, x, 1) Then
        y = y & vbCrLf & aTask.ID & ": " & aTask.Name
    End If
    Next aTask
    ' If No tasks exist then end'
    If Len(y) = 0 Then
        MsgBox "No Tasks with the text" & x & " found in the project", vbExclamation
        Else
            MsgBox y
        End If
    End If
End Sub

See images below

Example of this

ID    Task Name  Flag 1(Hydro)
1     Hydro 1    Yes
2     basket 1   No
3     Hydro 2   Yes

回答1:


This code will set a Flag field (in this case Flag1). If the task Name field contains the desired text the Flag will be set to Yes, otherwise it will be No.

Sub FlagTasks()

    Dim txt As String
    txt = InputBox("Flag tasks that include the following text in their names:")

    Dim tsk As Task
    For Each tsk In ActiveProject.Tasks
        tsk.Flag1 = (0 < InStr(1, tsk.Name, txt, 1))
    Next tsk

End Sub


来源:https://stackoverflow.com/questions/58634897/how-to-set-flag-field-to-yes-or-no-based-on-text-input-microsoft-project-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!