PRJ: How to Use the GanttBarFormat Method (126943)
The information in this article applies to:
- Microsoft Project 98 for Windows
- Microsoft Project for Windows 95 4.1
- Microsoft Project for Windows 95 4.1a
- Microsoft Project for Windows 4.0
- Microsoft Project for the Macintosh 4.0
This article was previously published under Q126943 SUMMARY
This article discusses two ways you can use the GanttBarFormat method in a
macro that loops through a set of tasks and formats them based on a
particular set of criteria.
MORE INFORMATION
The GanttBarFormat method is used to change the format of the Gantt Bars
from the default styles that have been applied using the Bar Styles command
on the Format menu. By default, the GanttBarFormat method applies to all
selected tasks.
Microsoft provides examples of Visual Basic procedures for illustration
only, without warranty either expressed or implied, including but not
limited to the implied warranties of merchantability and/or fitness for a
particular purpose. This Visual Basic procedure is provided 'as is' and
Microsoft does not guarantee that it can be used in all situations.
Microsoft does not support modifications of this procedure to suit customer
requirements for a particular purpose.
Below are two examples of macros that loop through tasks in the active
project and format those tasks that have a task name of a with a left
diagonal bar pattern and those that don't with a crossed line bar pattern.
To test these macros, create a project with three or four tasks with two of
the tasks having a task name of a.
NOTE: The Gantt Chart View must be active when you run these macros or you
will receive a run-time error.
Sample Macro 1
Including the TaskID named argument with the GanttBarFormat method allows
the macro to cycle through the tasks in the active project without having
to manually select them using a "SelectCellDown" or other equivalent
command. The following macro demonstrates this procedure:
Sub Macro1()
Dim t As Task
For Each t In ActiveProject.Tasks
'skip over blank rows
If Not t is Nothing then
If (t.Name = "a") Then
GanttBarFormat TaskID:=t.ID, MiddlePattern:=5
Else
GanttBarFormat TaskID:=t.ID, MiddlePattern:=10
End If
End If
Next t
End Sub
Sample Macro 2
The following example selects each task in the active project (using the
SelectCellDown method), tests the name field, and then applies the Gantt
bar formatting. The macro stops when a blank task is encountered. This
macro is slower than Sample Macro 1 because of the additional work
associated with the selection process. It is also more error prone because
it depends on a certain table layout and assumes that the "ActiveCell" is
the name field.
NOTE: This macro assumes that there are no blank rows between real tasks.
SelectBeginning
Do Until (ActiveCell = "")
If ActiveCell.Task.Name = "a" Then
GanttBarFormat MiddlePattern:=5
Else
GanttBarFormat MiddlePattern:=10
End If
SelectCellDown
Loop
End Sub
REFERENCES
For more information on the GanttBarFormat method search on the word
Gantt in the Visual Basic Reference Help.
Modification Type: | Major | Last Reviewed: | 11/25/2003 |
---|
Keywords: | kbcode kbhowto kbProgramming KB126943 |
---|
|