Solved

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

Posted on 2013-11-15
3
1,422 Views
Last Modified: 2016-08-31
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
Comment
Question by:childejc
3 Comments
 
LVL 19

Accepted Solution

by:
Ken Butters earned 500 total points
ID: 39652562
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
 

Author Closing Comment

by:childejc
ID: 39677292
Your suspicion was correct and your code works!  Thanks very much.  Looks like I need to learn some VBA.

thanks again

Eric
0
 

Expert Comment

by:Philip Day
ID: 41778138
This works in MS Project 2013, I just tried it!

Great solution Ken Butters!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
We were having a lot of "Heartbeat Alerts" in our SCOM environment, now "Heartbeat" in a SCOM environment for those of you who might not be familiar with SCOM is a packet of data sent from the agent to the management server on a regular basis, basic…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question