Solved

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

Posted on 2013-11-15
3
1,439 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

I wanted to share this with fellow Experts, who might not know. How often have you wanted to learn something, only to be set back by either restrictions imposed on "trial" or "evaluation" software?  How often have you had to rebuild a home networ…
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…
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
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 …

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