Solved

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

Posted on 2013-11-15
3
1,367 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

MS Access 2003 or later To MySQL Migration Project Hello All, this is my second article in the category of MS-OFFICE Automation. In internet I am not able to find any comprehensive resource on the Migration of MS Access back-end to MySQL so I fin…
The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
Viewers will learn the different options available in the Backstage view in Excel 2013.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now