Way to automatically select all boxes in network diagram

S

Steph

Hi -

Is there a way to automatically select all boxes in a network diagram? I
would like to write some code to format all boxes but can't seem to find a
way to do that via code.

Stephanie
 
J

JackD

Here is how I would do it:

Sub FormatMyBoxes()
'declare a variable to go through each task in the file
Dim boxNum As Integer

For boxNum = 1 To ActiveProject.Tasks.Count

'use that variable to select the corresponding box
BoxSet TaskID:=boxNum

'format that box
BoxFormat _
DataTemplate:="Summary", _
HorizontalGridlines:=True, _
VerticalGridlines:=False, _
BorderShape:=pjBoxWideRectangle, _
BorderColor:=pjLime, _
BorderWidth:=2, _
BackgroundColor:=pjWhite, _
BackgroundPattern:=pjBackgroundSolidFill, _
Reset:=False

'go to next box
Next boxNum
End Sub
 
S

Steph

Jack - excellent - thank you! Now here's what I ended up doing - I only
wanted to color certain tasks within a filter. I ended up having to specify
the conditions of that filter to color the right boxes ---

For x = 1 To ActiveProject.Tasks.Count
If ActiveProject.Tasks(x).Summary = False Then 'not summary
tskval = ActiveProject.Tasks(x).Text9
Select Case tskval
Case 1, 2, 5, 6 'marked as buffer
BoxSet taskId:=x
BoxFormat DataTemplate:="TOC",
BorderShape:=pjBoxWideRectangle, BorderColor:=pjLime, BorderWidth:=1,
Reset:=False, BackgroundPattern:=pjBackgroundHollow
End Select
End If
Next

Works like a charm!
 
J

JackD

You might want to change it just a bit so that it will work even if you are
not currently in the network diagram view.

Sub foos()
Dim t As Task
Dim ts As Tasks
ViewApply Name:="Network &Diagram"
Set ts = ActiveProject.Tasks
For x = 1 To ts.Count
Set t = ts(x)
If Not t.Summary Then
Select Case t.Text9
Case 1, 2, 5, 6 'marked as buffer
BoxSet TaskID:=x
BoxFormat DataTemplate:="TOC", _
BorderShape:=pjBoxWideRectangle, _
BorderColor:=pjLime, BorderWidth:=1, _
Reset:=False, _
BackgroundPattern:=pjBackgroundHollow
End Select
End If
Next t
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