如何根据文本输入将标志字段设置为是或否 - Microsoft-Project-VBA
How to Set Flag field to Yes or No Based on Text input - Microsoft-Project-VBA
我正在尝试根据文本是否在任务描述中来自动创建标志字段。目标是使用文本来搜索项目文件,并在标记字段中为每一行包含文本的文本添加 yes。
我能够使用行 ID 生成 MS 项目中的活动列表。
我不确定如何使用此列表在 Flag 字段中生成 "yes No"
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
见下图
Example of this
ID Task Name Flag 1(Hydro)
1 Hydro 1 Yes
2 basket 1 No
3 Hydro 2 Yes
此代码将设置一个标志字段(在本例中为 Flag1
)。如果任务名称字段包含所需的文本,则标志将设置为是,否则将为否。
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
我正在尝试根据文本是否在任务描述中来自动创建标志字段。目标是使用文本来搜索项目文件,并在标记字段中为每一行包含文本的文本添加 yes。
我能够使用行 ID 生成 MS 项目中的活动列表。
我不确定如何使用此列表在 Flag 字段中生成 "yes No"
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
见下图
Example of this
ID Task Name Flag 1(Hydro)
1 Hydro 1 Yes
2 basket 1 No
3 Hydro 2 Yes
此代码将设置一个标志字段(在本例中为 Flag1
)。如果任务名称字段包含所需的文本,则标志将设置为是,否则将为否。
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