S
Sean
I've tested this code informally and it has worked successfully with
repeated testing. Feel free to use it if you like. My goal is to have
it robust enough to distribute to end users and have them use this to
close out projects rather than going through multiple steps that only
introduce chances for error. Any input or feedback you have would be
great.
----------------------------------------
Sub Close_Out_Project()
' Macro Close Out Project
' Last Updated Aug 21 2007 by Sean Sullivan
' Closes out a project by setting remaining work to 0, setting
milestones to 100% complete,
' and changing resource booking types to Proposed.
Dim Tsk As Task
Dim Rsrc As Resource
Dim RowCount As Integer
'Since it uses the Resource Sheet, it will only work for resources
in the active project, not all projects.
'Must check for only one project to be open.
If Application.Projects.Count <> 1 Then
MsgBox ("This macro can only be run if one (1) project is
open. Please close all projects except the one you would like to close
out.")
Exit Sub
Else
End If
Application.ViewApply ("Enterprise Gantt Chart")
'Set remaining work = 0 for non-summary tasks
For Each Tsk In ActiveProject.Tasks
If Not Tsk Is Nothing Then
If Tsk.OutlineChildren.Count = 0 Then 'weeds out summary
tasks
Tsk.RemainingWork = 0
'For a task with no work done, this results in a 0 work
task and becomes a milestone.
'Set milestone %complete to 100
If Tsk.Work = 0 Then
Tsk.PercentComplete = 100
End If
End If
End If
Next Tsk
'Recalculate fields so everything is accurate
CalculateAll
If ActiveProject.Tasks(1).PercentComplete = 100 Then
MsgBox ("Project 100% Complete")
Else
MsgBox ("Please check to make sure your project is 100%
Complete.")
Exit Sub
End If
'Open Resource Sheet to edit Booking Types
Application.ViewApply ("Resource Sheet")
Application.TableApply ("Project Guide: Booking Resource Sheet")
'Set Counter Variable
RowCount = 1
'Set Resource Booking Type to Proposed
For Each Rsrc In ActiveProject.Resources
If Not (Rsrc Is Nothing) Then 'test for blank resource
SelectResourceField Row:=RowCount, Column:="Booking Type",
RowRelative:=False
SetResourceField Field:="Booking Type", Value:="Proposed"
End If
RowCount = RowCount + 1
Next Rsrc
If ActiveProject.Resources.Count = RowCount - 1 Then
MsgBox ("All Resources Changed")
Else 'if not all the resources changed, then manually adjust
through this dialog
MsgBox ("Please change resource bookings to 'Proposed'")
EnterpriseTeamBuilder
End If
Application.TableApply ("Entry")
Application.ViewApply ("Enterprise Gantt Chart")
End Sub
repeated testing. Feel free to use it if you like. My goal is to have
it robust enough to distribute to end users and have them use this to
close out projects rather than going through multiple steps that only
introduce chances for error. Any input or feedback you have would be
great.
----------------------------------------
Sub Close_Out_Project()
' Macro Close Out Project
' Last Updated Aug 21 2007 by Sean Sullivan
' Closes out a project by setting remaining work to 0, setting
milestones to 100% complete,
' and changing resource booking types to Proposed.
Dim Tsk As Task
Dim Rsrc As Resource
Dim RowCount As Integer
'Since it uses the Resource Sheet, it will only work for resources
in the active project, not all projects.
'Must check for only one project to be open.
If Application.Projects.Count <> 1 Then
MsgBox ("This macro can only be run if one (1) project is
open. Please close all projects except the one you would like to close
out.")
Exit Sub
Else
End If
Application.ViewApply ("Enterprise Gantt Chart")
'Set remaining work = 0 for non-summary tasks
For Each Tsk In ActiveProject.Tasks
If Not Tsk Is Nothing Then
If Tsk.OutlineChildren.Count = 0 Then 'weeds out summary
tasks
Tsk.RemainingWork = 0
'For a task with no work done, this results in a 0 work
task and becomes a milestone.
'Set milestone %complete to 100
If Tsk.Work = 0 Then
Tsk.PercentComplete = 100
End If
End If
End If
Next Tsk
'Recalculate fields so everything is accurate
CalculateAll
If ActiveProject.Tasks(1).PercentComplete = 100 Then
MsgBox ("Project 100% Complete")
Else
MsgBox ("Please check to make sure your project is 100%
Complete.")
Exit Sub
End If
'Open Resource Sheet to edit Booking Types
Application.ViewApply ("Resource Sheet")
Application.TableApply ("Project Guide: Booking Resource Sheet")
'Set Counter Variable
RowCount = 1
'Set Resource Booking Type to Proposed
For Each Rsrc In ActiveProject.Resources
If Not (Rsrc Is Nothing) Then 'test for blank resource
SelectResourceField Row:=RowCount, Column:="Booking Type",
RowRelative:=False
SetResourceField Field:="Booking Type", Value:="Proposed"
End If
RowCount = RowCount + 1
Next Rsrc
If ActiveProject.Resources.Count = RowCount - 1 Then
MsgBox ("All Resources Changed")
Else 'if not all the resources changed, then manually adjust
through this dialog
MsgBox ("Please change resource bookings to 'Proposed'")
EnterpriseTeamBuilder
End If
Application.TableApply ("Entry")
Application.ViewApply ("Enterprise Gantt Chart")
End Sub