Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Monitoring vmware 6 with SCOM 6 272
Clean Uninstall of VS Professional 2015 5 51
Port v1 4 60
Access DB on open (All Objects) 5 61
Problem: You created a new custom form in Outlook for your contacts (added fields, deleted fields, changed the layout of fields, whatever) and made it the default form for contacts. The good news is that all new contacts will utilize the new form. T…
Many companies are making the switch from Microsoft to Google Apps (https://www.google.com/work/apps/business/). Use this article to learn more about what Google Apps has to offer and to help if you’re planning on migrating to Google Apps. It is …
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 …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

930 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

9 Experts available now in Live!

Get 1:1 Help Now