【发布时间】:2021-12-12 01:59:02
【问题描述】:
我的代码将过滤器应用于项目(仅显示下周特定资源的活动),我需要捕获过滤器不返回任何内容的实例。
我找到了这个article,它导致了这个MS Entry。从这里我想出了测试:
If ActiveSelection.Tasks Is Nothing Then GoTo NextResource
退出当前资源循环并转到下一个,但是,这不起作用。错误 (424) 仅在我尝试使用 ActiveSelection 时生成
上下文的代码片段:
For Each Resource In Proj.Resources
If Not (Resource Is Nothing) Then
If Resource.Work > 0 Then
'setup and apply filter for each resource
FilterEdit name:="filter4people", TaskFilter:=True, Create:=True, OverwriteExisting:=True, FieldName:="Start", Test:="is less than or equal to", Value:=finish, ShowInMenu:=True, ShowSummaryTasks:=True
FilterEdit name:="filter4people", TaskFilter:=True, FieldName:="", NewFieldName:="% Complete", Test:="is less than", Value:="100%", Operation:="And", ShowSummaryTasks:=True
FilterEdit name:="filter4people", TaskFilter:=True, FieldName:="", NewFieldName:="Resource names", Test:="contains", Value:=Resource.name, Operation:="And", ShowSummaryTasks:=True
FilterApply "filter4people" ' apply the filter
If Not (Err.Number = 91 Or Err.Number = 0) Then ' saw an error applying filter
Err.Clear ' clear out the error
GoTo NextResource ' jump to the next resource
End If
Application.SelectSheet 'need to select the sheet so that ActiveSelection works properly
'CStr(ActiveSelection.Tasks.Count)
If ActiveSelection.Tasks Is Nothing Then GoTo NextResource
【问题讨论】:
-
听起来 ActiveSelection 没什么,所以你的代码也应该检查这个。
-
@BrianMStafford,输入
If ActiveSelection Is Nothing Then GoTo NextResource并没有改变行为。 Err.number 保持在 0 并且代码继续像以前一样失败 -
然而,进一步的测试表明,在一种测试情况下,它确实返回了 0 而不是什么也没有。这是有希望的,我会做更多的测试来确认它是否可以按需工作。
标签: vba ms-project