Search in Task Name field, if condition met Show (or not) subtask

N

NicoCaps

Hi all,

In order to automatically produce a planning with a specific layout, I would
like to create a VB macro which searches through all the tasks for specific
key words and depending on this show or hide the associated subtask.

It'll be less consuming to show all the tasks of the project and then to
fold the targeted sub tasks

For example if the sub task contains one of the following words: "General
Documentation", "Project Milestones" or "Manufacturing" I'd like it to be
hidden. On the contrary therest of the subtasks should show all of the tasks.
Does anyone know a light code which could do this easily?

Thanks for your help and sorry for the newbie question, I have trying
various methods but I don't know how to find an effective one only working on
specific keywords.

Nico
 
N

NicoCaps

Sorry I forgot to post the code I came up with when recording manually the
macro

Sub Search_And_Hide()
SelectSheet
OutlineShowSubTasks
OutlineShowSubTasks
OutlineShowSubTasks
OutlineShowSubTasks
Find Field:="Nom", Test:="Contient", Value:="Project Milestones",
Next:=True, MatchCase:=False
OutlineHideSubTasks
Find Field:="Nom", Test:="Contient", Value:="Documentation", Next:=True,
MatchCase:=False
FindNext
FindNext
OutlineHideSubTasks
Find Field:="Nom", Test:="Contient", Value:="Documentation", Next:=True,
MatchCase:=False
OutlineHideSubTasks
Find Field:="Nom", Test:="Contient", Value:="Documentation", Next:=True,
MatchCase:=False
OutlineHideSubTasks
Find Field:="Nom", Test:="Contient", Value:="Documentation", Next:=True,
MatchCase:=False
OutlineHideSubTasks
Find Field:="Nom", Test:="Contient", Value:="Documentation", Next:=True,
MatchCase:=False
OutlineHideSubTasks
SelectTaskField Row:=0, Column:="Nom"
Find Field:="Nom", Test:="Contient", Value:="CVT PCM BE - Detailed
Design", Next:=True, MatchCase:=False
OutlineHideSubTasks
Find Field:="Nom", Test:="Contient", Value:="CONVERTER UNIT 1
Manufacturing", Next:=True, MatchCase:=False
OutlineHideSubTasks
Find Field:="Nom", Test:="Contient", Value:="CONVERTER UNIT 2
Manufacturing", Next:=True, MatchCase:=False
OutlineHideSubTasks
SelectTaskField Row:=0, Column:="Nom"
Find Field:="Nom", Test:="Contient", Value:="MOTOR UNIT 1
Manufacturing", Next:=True, MatchCase:=False
OutlineHideSubTasks
SelectTaskField Row:=0, Column:="Nom"
SetTaskField Field:="Nom", Value:="MOTOR UNIT 1 Manufacturing"
SelectTaskField Row:=1, Column:="Nom"
SelectTaskField Row:=-1, Column:="Nom"
Find Field:="Nom", Test:="Contient", Value:="MOTOR UNIT 2
Manufacturing", Next:=True, MatchCase:=False
OutlineHideSubTasks
SelectTaskField Row:=0, Column:="Nom"
Find Field:="Nom", Test:="Contient", Value:="WWH1 Manufacturing",
Next:=True, MatchCase:=False
OutlineHideSubTasks
SelectTaskField Row:=0, Column:="Nom"
Find Field:="Nom", Test:="Contient", Value:="WWH2 Manufacturing",
Next:=True, MatchCase:=False
OutlineHideSubTasks
End Sub
 
J

John

NicoCaps said:
Sorry I forgot to post the code I came up with when recording manually the
macro

Sub Search_And_Hide()
SelectSheet
OutlineShowSubTasks
OutlineShowSubTasks
OutlineShowSubTasks
OutlineShowSubTasks
Find Field:="Nom", Test:="Contient", Value:="Project Milestones",
Next:=True, MatchCase:=False
OutlineHideSubTasks
Find Field:="Nom", Test:="Contient", Value:="Documentation", Next:=True,
MatchCase:=False
FindNext
FindNext
OutlineHideSubTasks
Find Field:="Nom", Test:="Contient", Value:="Documentation", Next:=True,
MatchCase:=False
OutlineHideSubTasks
Find Field:="Nom", Test:="Contient", Value:="Documentation", Next:=True,
MatchCase:=False
OutlineHideSubTasks
Find Field:="Nom", Test:="Contient", Value:="Documentation", Next:=True,
MatchCase:=False
OutlineHideSubTasks
Find Field:="Nom", Test:="Contient", Value:="Documentation", Next:=True,
MatchCase:=False
OutlineHideSubTasks
SelectTaskField Row:=0, Column:="Nom"
Find Field:="Nom", Test:="Contient", Value:="CVT PCM BE - Detailed
Design", Next:=True, MatchCase:=False
OutlineHideSubTasks
Find Field:="Nom", Test:="Contient", Value:="CONVERTER UNIT 1
Manufacturing", Next:=True, MatchCase:=False
OutlineHideSubTasks
Find Field:="Nom", Test:="Contient", Value:="CONVERTER UNIT 2
Manufacturing", Next:=True, MatchCase:=False
OutlineHideSubTasks
SelectTaskField Row:=0, Column:="Nom"
Find Field:="Nom", Test:="Contient", Value:="MOTOR UNIT 1
Manufacturing", Next:=True, MatchCase:=False
OutlineHideSubTasks
SelectTaskField Row:=0, Column:="Nom"
SetTaskField Field:="Nom", Value:="MOTOR UNIT 1 Manufacturing"
SelectTaskField Row:=1, Column:="Nom"
SelectTaskField Row:=-1, Column:="Nom"
Find Field:="Nom", Test:="Contient", Value:="MOTOR UNIT 2
Manufacturing", Next:=True, MatchCase:=False
OutlineHideSubTasks
SelectTaskField Row:=0, Column:="Nom"
Find Field:="Nom", Test:="Contient", Value:="WWH1 Manufacturing",
Next:=True, MatchCase:=False
OutlineHideSubTasks
SelectTaskField Row:=0, Column:="Nom"
Find Field:="Nom", Test:="Contient", Value:="WWH2 Manufacturing",
Next:=True, MatchCase:=False
OutlineHideSubTasks
End Sub

Nico,
A couple of questions. First, let's clarify some terms. You use the
terms "tasks", "sub task", and "subtasks". In Project a summary line
isn't really a task even though it is often referred to as such. There
may be several levels of summary with the actual activities that have
resources assigned being performance tasks, although they are often
referred to as subtasks.

From your post it is not clear if you are trying to hide all performance
tasks under a particular summary or if you want to only hide select
performance tasks under a given summary. In Project it is only possible
to hide ALL performance tasks (subtasks) of a given summary, you cannot
hide selected performance tasks. You can however, create a filter that
will suppress displaying any individual or group of tasks that meet (or
do not meet) the filter criteria.

Recorded macro code (foreground processing) is generally much less
efficient than object level code (background processing). Hence there is
an easier code structure that could be used to accomplish what you want,
once we know what that is. However, you already have a recorded macro
and the main question is, does it do what you need?

John
Project MVP
 
N

NicoCaps

Nico,
A couple of questions. First, let's clarify some terms. You use the
terms "tasks", "sub task", and "subtasks". In Project a summary line
isn't really a task even though it is often referred to as such. There
may be several levels of summary with the actual activities that have
resources assigned being performance tasks, although they are often
referred to as subtasks.

From your post it is not clear if you are trying to hide all performance
tasks under a particular summary or if you want to only hide select
performance tasks under a given summary. In Project it is only possible
to hide ALL performance tasks (subtasks) of a given summary, you cannot
hide selected performance tasks. You can however, create a filter that
will suppress displaying any individual or group of tasks that meet (or
do not meet) the filter criteria.

Recorded macro code (foreground processing) is generally much less
efficient than object level code (background processing). Hence there is
an easier code structure that could be used to accomplish what you want,
once we know what that is. However, you already have a recorded macro
and the main question is, does it do what you need?

John
Project MVP

Hi John,

Thanks for your answer.

Yes the pasted macro does its job perfectly. However I have several
plannings based on the same structure logic. Being able to have a generic
macro that could be applied to all of them would help me greatly.

Sorry for being unclear, with the proper vocabulary, what I want to do is
loop through all the summary tasks in the planning and fold only those
containing specific keywords (Documentation, Detailed Design,...). This would
allow me to hide unneeded performance tasks under them.

Could you please refer me to a code that already exists?

Thanks

Nico
 
J

John

Nico,
A couple of questions. First, let's clarify some terms. You use the
terms "tasks", "sub task", and "subtasks". In Project a summary line
isn't really a task even though it is often referred to as such. There
may be several levels of summary with the actual activities that have
resources assigned being performance tasks, although they are often
referred to as subtasks.

From your post it is not clear if you are trying to hide all performance
tasks under a particular summary or if you want to only hide select
performance tasks under a given summary. In Project it is only possible
to hide ALL performance tasks (subtasks) of a given summary, you cannot
hide selected performance tasks. You can however, create a filter that
will suppress displaying any individual or group of tasks that meet (or
do not meet) the filter criteria.

Recorded macro code (foreground processing) is generally much less
efficient than object level code (background processing). Hence there is
an easier code structure that could be used to accomplish what you want,
once we know what that is. However, you already have a recorded macro
and the main question is, does it do what you need?

John
Project MVP

Hi John,

Thanks for your answer.

Yes the pasted macro does its job perfectly. However I have several
plannings based on the same structure logic. Being able to have a generic
macro that could be applied to all of them would help me greatly.

Sorry for being unclear, with the proper vocabulary, what I want to do is
loop through all the summary tasks in the planning and fold only those
containing specific keywords (Documentation, Detailed Design,...). This would
allow me to hide unneeded performance tasks under them.

Could you please refer me to a code that already exists?

Thanks

Nico[/QUOTE]

Nico,
Thanks for the clarification on what you want. Now I can help you.

I have no idea whether code already exists to do what you want, but it's
simple enough that I threw together the code below. Note that you can
add any number of InStr criteria to the "If" statement to look for the
keywords you want. To make the code even more generic, you could solicit
user input for the desired keywords using the InputBox Function.

Option Compare Text
Sub Collapse_Summaries()
Dim t As Task

FilterEdit Name:="no sum", taskfilter:=True, create:=True,
overwriteexisting:=True, _
FieldName:="summary", test:="equals", Value:="no", _
ShowInMenu:=False, showsummarytasks:=False
FilterApply Name:="no sum"
SelectTaskColumn
For Each t In ActiveSelection.Tasks
If InStr(1, t.Name, "your string 1") > 0 Or _
Instr(1, t.Name, "your string 2") > 0 Or _
[etc.] Then
t.OutlineParent.OutlineHideSubTasks
End If
Next t
FilterApply Name:="all tasks"

End Sub

Hope this helps.
John
 
N

NicoCaps

Hi John,

Thank you for your answer I had to do some minor adaptations but the core
code works perfectly. Hereafter pasted the code which works fine for my needs.

Adaptations done:
- Changed the filter properties to the French version of MS project
(FieldName, test, Value).
- I doubled the filter so that I could fold not only summary tasks above
performance tasks but also summary tasks above other summary tasks, I called
it "Récap only" and then applied the one you gave me to fold only secondary
summary tasks.
- Changed the "all tasks" filter name to the french name.

I may be wrong, and it surely could have been done in a smarter way, but it
was the only way I could find to make it work. Hope this helps someone with
the same problem.

Cheers and thanks again!
Rehards

Nico

Option Compare Text
Sub Collapse_Summaries()
Dim t As Task

FilterEdit Name:="Récap only", taskfilter:=True, create:=True,
overwriteexisting:=True, _
FieldName:="Récapitulative", test:="Égal à", Value:="oui", _
ShowInMenu:=False, showsummarytasks:=False

FilterEdit Name:="No Récap", taskfilter:=True, create:=True,
overwriteexisting:=True, _
FieldName:="Récapitulative", test:="Égal à", Value:="non", _
ShowInMenu:=False, showsummarytasks:=False

FilterApply Name:="Récap only"
SelectTaskColumn
For Each t In ActiveSelection.Tasks
If InStr(1, t.Name, "your string 1") > 0 Or _
Instr(1, t.Name, "your string 2") > 0 Or _
[etc.] Then
t.OutlineParent.OutlineHideSubTasks
End If
Next t

FilterApply Name:="No Récap"
SelectTaskColumn
For Each t In ActiveSelection.Tasks
If InStr(1, t.Name, "your string 1") > 0 Or _
Instr(1, t.Name, "your string 2") > 0 Or _
[etc.] Then
t.OutlineParent.OutlineHideSubTasks
End If
Next t

FilterApply Name:="Toutes les tâches"

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top