• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1562
  • Last Modified:

MS Project 2010 - collapsing completed summary tasks - need VBA help

In MSP 2010 it is unfortunately not possible to apply a filter and then selectively expand a summary task to see the tasks that sit under that summary that were filtered out.

Someone else asked for a solution to this question in this thread here

The solution is to use VBA, but I have very little knowledge of VBA and don't know how to make the code work.

This is the suggested code

Sub t()
Dim tsk As Task

    For Each tsk In ActiveProject.Tasks
        If tsk.Summary = True Then
'            Dim s As Integer
'            s = tsk.ID
'
            If tsk.PercentComplete >= 100 Then
                tsk.OutlineHideSubTasks
            Else
                tsk.OutlineShowSubTasks
               
               
            End If
        End If
    Next
End Sub

I am able to open the VBA window and paste in this code, but when I try to run it I get a pop up saying Run-time error 91 Object variable or With block variable not set.

What am I doing wrong?

Thanks

Eric
0
childejc
Asked:
childejc
1 Solution
 
Ken ButtersCommented:
I don't have MS project 2000.... but I do know VBA.

The error you mentioned usually happens because a variable that should point to an object points to nothing instead.

The variable I see in your routine that should point to an object is tsk.

can you try adding something like this to your code... right after the "For Each"?

if tsk is nothing then
    msgbox("tsk found that set to nothing")
end if

Open in new window


that way... it will check to see if this is what is wrong.

if that is what is wrong you could use this code to fix it:

Sub t()
Dim tsk As Task

    For Each tsk In ActiveProject.Tasks
        If not tsk is nothing then
           If tsk.Summary = True Then
               If tsk.PercentComplete >= 100 Then
                   tsk.OutlineHideSubTasks
               Else
                   tsk.OutlineShowSubTasks
                
                
               End If
           End If
        End If
    Next
End Sub

Open in new window

0
 
childejcAuthor Commented:
Your suspicion was correct and your code works!  Thanks very much.  Looks like I need to learn some VBA.

thanks again

Eric
0
 
Philip DayCommented:
This works in MS Project 2013, I just tried it!

Great solution Ken Butters!
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now