ms-project - ms-project 如何将资源自定义字段复制到任务自定义字段
问题描述
在 MS Project (2013) 中,谁能告诉我如何将资源自定义字段(从资源视图选项卡)复制到子项目任务的自定义字段(任务视图选项卡)?找到以下内容从分配字段(资源使用视图)复制到任务字段,但我不知道如何处理资源字段...
Sub CopyAssignmentFieldToTask()
Dim t As Task
Dim ts As Tasks
Dim a As Assignment
Set ts = ActiveProject.Tasks
For Each t In ts
If Not t Is Nothing Then
t.Text5 = ""
For Each a In t.Assignments
'change the following line to use
'for a different custom field
t.Text5 = t.Text5 & ", " & a.Text5
Next a
End If
Next t
End Sub
来源:http: //zo-d.com/blog/archives/programming/working-with-task-and-assignment-fields-vba.html
编辑:非常感谢雷切尔......对于未来的参考,这是通过子项目循环的完整答案:
Sub CopyResourceUnitstoTasksv2()
Dim t As Task
Dim a As Assignment
Dim mProj As Project
Set mProj = ActiveProject
For Each Subproject In mProj.Subprojects
For Each t In ActiveProject.Tasks
If Not t Is Nothing Then
For Each a In t.Assignments
t.Number2 = a.Resource.Number1
Next a
End If
Next t
Next Subproject
End Sub
解决方案
Assignment对象有一个返回Resource对象的Resource属性:
Sub CopyResourceFieldToTask()
Dim t As Task
Dim a As Assignment
Dim t5 As String
For Each t In ActiveProject.Tasks
If Not t Is Nothing Then
t5 = vbNullString
For Each a In t.Assignments
t5 = t5 & ", " & a.Resource.Text5
Next a
If Len(t5) > 2 Then
t.Text5 = Mid(t5, 3)
Else
t.Text5 = vbNullString
End If
End If
Next t
End Sub
推荐阅读
- java - 从 url 读取 csv 文件
- r - 如何在软件 R 中没有“for”的情况下高效编程?
- php - 为什么 wp 动作钩子不适用于基于特定 url 字符串删除短代码的函数
- visual-studio - 如何在 Visual Studio 解决方案中升级 CUDA 版本?
- mysql - findAllUseCountTop1ByIsActiveOrderById(Boolean isActive) 不会生成带有“LIMIT 1”的查询
- c++ - 使用 std::enable_if 的多变量模板特化
- sql - 谷歌表格查询功能不在
- python - String.split 使用正则表达式忽略方括号内的内容
- javascript - 计算购物车的总和
- javascript - 如何停止创建无休止的事件序列?