-
VBA Beginner Help - Format Gantt Bars
Hello!
I am a definite VBA beginner trying (unsuccessfully) to compile code snippets from examples on the web. I've been banging my head on the wall for a few hours plugging in different variations of code, but to no avail.
I am inserting project files into a master file and want to preserve the Gantt Bar formatting (color, primarily). Since the formats are dropped on the insert, I decided to set the text30 field in the subproject file to different values (i.e. grn, gry) related to their desired color and then use VBA to format the Gantt Bars in the master file based on those values. Here is the code:
Sub MarkText30()
Dim tskT As Task
For Each tskT In ActiveProject.Tasks
Select Case tskT.Text30
Case "grn"
GanttBarFormat TaskID:=tskT.ID, Reset:=True
GanttBarFormat TaskID:=tskT.ID, MiddleColor:=pjGreen, StartColor:=pjGreen, EndColor:=pjGreen
Case "gry"
GanttBarFormat TaskID:=tskT.ID, Reset:=True
GanttBarFormat TaskID:=tskT.ID, MiddleColor:=pjGray, StartColor:=pjGray, EndColor:=pjGray
Case "rd"
GanttBarFormat TaskID:=tskT.ID, Reset:=True
GanttBarFormat TaskID:=tskT.ID, MiddleColor:=pjRed, StartColor:=pjRed, EndColor:=pjRed
Case "mar"
GanttBarFormat TaskID:=tskT.ID, Reset:=True
GanttBarFormat TaskID:=tskT.ID, MiddleColor:=pjMaroon, StartColor:=pjMaroon, EndColor:=pjMaroon
Case Else
End Select
Next tskT
End Sub
What looks like good code returns different runtime errors, most frequently Runtime Error 91 on the Select Case line. The code gives the same error in a project file without inserted projects. Any ideas? Also, is this the best solution to the root problem (i.e. the subproject Gantt Bar color format not transferring to the master file)?
BTW, I am working in Project 2007, but saving the master file in 2003 since the inserted files are 2003.
I greatly appreciate your time and assistance!
RookE
-
Resolved!
Fixed it! Acquired some help from another site (Project Programming Archives).
Sub MarkText30()
Dim tskT As Tasks
Dim t As Task
Set tskT = ActiveProject.Tasks
For Each t In tskT
If Not t Is Nothing Then
If Not t.Summary Then
Select Case t.Text30
Case "grn"
GanttBarFormat TaskID:=t.ID, Reset:=True
GanttBarFormat TaskID:=t.ID, MiddleColor:=pjGreen, StartColor:=pjGreen, EndColor:=pjGreen
Case "gry"
GanttBarFormat TaskID:=t.ID, Reset:=True
GanttBarFormat TaskID:=t.ID, MiddleColor:=pjGray, StartColor:=pjGray, EndColor:=pjGray
Case "rd"
GanttBarFormat TaskID:=t.ID, Reset:=True
GanttBarFormat TaskID:=t.ID, MiddleColor:=pjRed, StartColor:=pjRed, EndColor:=pjRed
Case "mar"
GanttBarFormat TaskID:=t.ID, Reset:=True
GanttBarFormat TaskID:=t.ID, MiddleColor:=pjMaroon, StartColor:=pjMaroon, EndColor:=pjMaroon
Case Else
End Select
End If
End If
Next t
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules