【发布时间】:2015-08-19 08:53:55
【问题描述】:
基本上,正如标题所暗示的那样,我正在尝试遍历一个名为“Text3”的自定义字段,该字段与“任务所有者”相关联,一次下拉过滤一个资源。我是新手,所以请多多包涵。
这是我的代码:
Sub Macro1()
' Macro Macro1
' Macro Recorded Fri 5/29/15 by Valencia, Jonathan.
' suppose to go down the task owner filtered list for each resource and
' print to xps
Dim res As resource, name As String
'apply the gantt view first
ViewApply name:="gantt chart"
'expand all tasks
OutlineShowAllTasks
'apply the late task filter
FilterApply name:="Late Tasks"
For Each res In ActiveProject.Resources
name = res.name
'apply filter to task owner as the resource
'checks to see if filter is set on the application first
If Not ActiveProject.AutoFilter Then
Application.AutoFilter
End If
Application.SetAutoFilter FieldName:="Text3", _
FilterType:=pjAutoFilterCustom, _
Test1:="contains", Criteria1:=name
'export to xps with the resources' name
DocumentExport FileName:=name, FileType:=pjXPS
Next res
End Sub
*************************************************************************
我遇到的问题是它没有为该特定资源设置过滤器,而只是将其留空。如果我给出标准,例如“john smith”,它会起作用,但我正在尝试使用变量名称作为字符串来遍历所有资源。
任何帮助将不胜感激。 谢谢。
【问题讨论】:
-
您确定 Text3 中的值与您的资源名称完全匹配吗?我试过你的代码,对我来说效果很好。例如,我创建了一个名为“Rachel”的资源,并将该值放在 Text3 字段中用于一些后期任务,并且过滤器运行良好。
-
我刚查了一下,你说得对,名字不完全匹配......
-
那么我将如何遍历该过滤列表?是否有一个数组包含为该过滤列表存储的所有值?
标签: vba ms-office ms-project