vba - 如何根据文本输入将标志字段设置为是或否 - Microsoft-Project-VBA
问题描述
我正在尝试根据文本是否在任务描述中自动创建标志字段。目标是使用文本搜索项目文件,并在带有文本的每一行中,在标志字段中将“是”放在它旁边。
我能够使用行 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
推荐阅读
- command - SCP 命令在空手道项目中不起作用 - 它引发命令错误:无法运行程序 scp.exe:CreateProcess 错误 = 2
- oracle - 在 Oracle 中调用以 $ 字符开头的值
- linux - 使用 cut 组合 csv 文件以选择一列并粘贴以组合文件
- python - 如何在 Django Rest Framework 中为基于函数的视图添加过滤
- ios - 过多的脏内存
- flutter - 如何实现自定义微调器以在颤动中选择时间
- css - 如何通过 select2 显示完整的大文本选项(没有水平滚动)?参考图片
- php - 具有多态关系的 Laravel 全局访问
- python - GeoPandas 地图:以国家为中心(并在经度 180 度处加入分割几何图形)
- reactjs - 在react redux和saga中调度完成后获取状态变量?