问题
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