Project: Macro to Display Work Progress in Gantt Chart

Q126389


The information in this article applies to:


SUMMARY

Using Microsoft Project, you can use a macro to create a custom Gantt bar whose length is calculated as a percentage of a different task bar. This macro can be useful for displaying different types of progress information on a task that is not normally available in Gantt bar form.

For example, although Microsoft Project does not provide a standard Gantt bar that represents the percentage of work performed on a task, you can create such a bar by modifying the Gantt Chart and creating a custom macro.


MORE INFORMATION

The default Gantt Chart in Microsoft Project includes a Progress bar which visually represents the % Complete of a given task, which is based on the task's duration. However, there is no direct way to create a corresponding Work Progress bar to represent the % Work Complete of a given task. However, you can use a Visual Basic macro to create such a bar.

In order to create a custom bar in the Gantt chart, you must specify two date fields between which the bar should be drawn. For the Work Progress bar, these two fields will be Start and Start5. The Start5 field will be calculated by the macro in such a way that the length of this bar accurately represents the % Work Complete of the task.

Before you create the custom macro, add the new bar definition to your Gantt Chart by following these steps:

  1. While in the Gantt Chart view, from the Format menu, choose Bar Styles.


  2. On the first blank row in the Bar Styles dialog, enter the following bar definition:
    
       Name            Show For...Tasks   Row    From     To
       ---------------------------------------------------------
    
       Work Progress   Normal             1      Start    Start5 
    Select a style for the bar using the options on the Bar tab at the bottom of the Bar Styles dialog.


  3. Choose OK to close this dialog box.


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.

To create the custom macro, do the following:

  1. From the Tools menu, choose Macros.


  2. Choose New to bring up the New Macro dialog box.


  3. Enter CalcWorkProgress in the Macro Name field, then choose OK.


  4. In the Module Editor view, enter the code for the procedure that follows, exactly as shown:


  5. 
       Sub CalcWorkProgress()
    
          Dim tskIndex As Task
          Dim dWorkLen As Double
          Dim dTaskLen As Double
    
          For Each tskIndex In ActiveProject.Tasks
           If Not (tskIndex Is Nothing) Then
    
          ' Get length of normal task bar in elapsed days.
            dTaskLen = tskIndex.Finish - tskIndex.Start
    
          ' Calc length of Work Progress bar in elapsed days.
            dWorkLen = tskIndex.PercentWorkComplete / 100 * dTaskLen
    
          ' Calc a date corresponding to this bar length.
            tskIndex.Start5 = tskIndex.Start + dWorkLen
    
           End If
          Next tskIndex
    
       End Sub 

Running the Macro

You should run the macro any time you want to update the Work Progress bars in your Gantt Chart.

To run this macro, do the following:

  1. From the Tools menu, choose Macros.


  2. From the list of macros, select CalcWorkProgress, and then choose Run.


Additional query words:

Keywords :
Issue type : kbinfo
Technology : kbHWMAC kbOSMAC kbProjectSearch kbProject400Mac kbProjectMacSearch kbProject400


Last Reviewed: November 5, 2000
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.