Share via

Project loop through filtered tasks

Anonymous
2013-10-10T09:59:31+00:00

Is there a way to determine if a task meets the currently selected filter?  I need a loop to process only the filtered tasks.

Sub test()

Dim T As Task

For Each T In ActiveProject.Tasks

' do something

Next T

End Sub

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

5 answers

Sort by: Most helpful
  1. John Project 49,710 Reputation points Volunteer Moderator
    2013-10-15T17:16:37+00:00

    WoodyPMP,

    You can use ActiveProject.CurrentView and ActveProject.CurrentFilter to determine what is active.

    John

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2013-10-15T16:16:01+00:00

    Unfortunately, I don't have the luxury of knowing the name of the filter in advance.  It would be nice if the Task class had a Visible property.  I need to be able to loop through all tasks or only those that are visible.

    Dim iResponse As Integer, ts As Tasks

    ' Determine if user wants to export all tasks or visible tasks only

    iResponse = MsgBox("Export visible/filtered tasks only", vbYesNoCancel)

    Select Case iResponse

    Case vbYes

    SelectAll

    Set ts = ActiveSelection.Tasks

    Case vbNo

    Set ts = ActiveProject.Tasks

    Case vbCancel

    Exit Sub

    End Select

    Was this answer helpful?

    0 comments No comments
  3. John Project 49,710 Reputation points Volunteer Moderator
    2013-10-15T15:18:54+00:00

    WoodyPMP,

    Well yeah, that's right. Since "SelectAll", or any select statement, is operating on the active view pane, you need to insure that the active pane is the one with the filtered task set. Nothing "unreliable" about it, that's the way it works.

    One solution is to add a statement to your code to activate the appropriate filtered view, then use the SelectAll for the ActiveSelection.Tasks set.

    John

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2013-10-15T15:07:42+00:00

    I had tried that approach already. Unfortunately, I found it to be somewhat unreliable.  It requires that you call SelectAll method.  That method sometimes throws error depending on what part of the interface has the focus.  For instance, if you have a split view and the focus is in the task form.  When you call SelectAll, you get Run-time error 1100 (The method is not available in this situation)

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2013-10-10T12:41:08+00:00

    Hi,

    Yes there is:

    Sub Filtered

    Select all

    for each Job in activeselection.tasks

    ...

    next

    end sub

    Greetings,

    Was this answer helpful?

    0 comments No comments