在应用到项目任务之前检查资源的可用性 VBA MS Project
Check the availability of a resource before applying to a project task VBA MS Project
我正在使用 VBA 根据举行 session 的地点、房间容量和房间可用性将资源(房间)分配给 MS Project 中的任务。我被困在房间可用性部分。我假设必须有一些方法可以连接到资源的可用性属性 object 以快速确定资源是否已经应用于另一个任务。
干杯
Sub Allocate_Rooms()
'Allocating a Resource (Room) to a Task based on the location of the
facility, room capacity and availability
Dim T As Task
Dim R As Resource
For Each T In ActiveProject.Tasks
i = 0
If Left(T.Name, 1) <> "M" Then 'Checks to see if the task is a valid Module session
GoTo SkipT
End If
For Each R In ActiveProject.Resources
If Left(R.Name, 2) <> "R-" Then 'Skips resources that are not rooms
GoTo SkipR
End If
If T.Text5 = R.Text3 Then 'The Resource (Room) is in the same facility as the sesssion that is being held
If T.Text1 <= R.Text1 Then 'Check the number of users is less than or equal to the Room Capacity
'If ??????
'Something in here to check the availability of the Resource (Room). This would be based on the set calendar
'of the Resource and also would check if the room has been allocated to another Task in the Project
T.ResourceNames = R.Name 'Assign the resource to the task
Goto SkipT
'End if
End If
End If
SkipR:
Next R 'next Resource
SkipT:
Next T 'Next Task
End Sub
使用 TimeScaleData method of the Resource object to return a TimeScaleValues 对象可用于确定在给定时间段(例如任务的持续时间)内已分配给该资源的工作量。例如:
Dim tsvs As TimeScaleValues
Set tsvs = R.TimeScaleData(T.Start, T.Finish, pjResourceTimescaledWork, pjTimescaleYears)
If tsvs(1).Value = 0 Then
T.ResourceNames = R.Name
' exit loop now that room is assigned
End If
请注意,此处使用的单位是 pjTimescaleYears
,因此任务期间资源的全部工时都集中到一个值中(除非任务跨越一年以上)。如果您要使用默认值 pjTimescaleDays
并且任务跨度超过一天,则 tsvs
将有多个元素需要检查。
我正在使用 VBA 根据举行 session 的地点、房间容量和房间可用性将资源(房间)分配给 MS Project 中的任务。我被困在房间可用性部分。我假设必须有一些方法可以连接到资源的可用性属性 object 以快速确定资源是否已经应用于另一个任务。
干杯
Sub Allocate_Rooms()
'Allocating a Resource (Room) to a Task based on the location of the
facility, room capacity and availability
Dim T As Task
Dim R As Resource
For Each T In ActiveProject.Tasks
i = 0
If Left(T.Name, 1) <> "M" Then 'Checks to see if the task is a valid Module session
GoTo SkipT
End If
For Each R In ActiveProject.Resources
If Left(R.Name, 2) <> "R-" Then 'Skips resources that are not rooms
GoTo SkipR
End If
If T.Text5 = R.Text3 Then 'The Resource (Room) is in the same facility as the sesssion that is being held
If T.Text1 <= R.Text1 Then 'Check the number of users is less than or equal to the Room Capacity
'If ??????
'Something in here to check the availability of the Resource (Room). This would be based on the set calendar
'of the Resource and also would check if the room has been allocated to another Task in the Project
T.ResourceNames = R.Name 'Assign the resource to the task
Goto SkipT
'End if
End If
End If
SkipR:
Next R 'next Resource
SkipT:
Next T 'Next Task
End Sub
使用 TimeScaleData method of the Resource object to return a TimeScaleValues 对象可用于确定在给定时间段(例如任务的持续时间)内已分配给该资源的工作量。例如:
Dim tsvs As TimeScaleValues
Set tsvs = R.TimeScaleData(T.Start, T.Finish, pjResourceTimescaledWork, pjTimescaleYears)
If tsvs(1).Value = 0 Then
T.ResourceNames = R.Name
' exit loop now that room is assigned
End If
请注意,此处使用的单位是 pjTimescaleYears
,因此任务期间资源的全部工时都集中到一个值中(除非任务跨越一年以上)。如果您要使用默认值 pjTimescaleDays
并且任务跨度超过一天,则 tsvs
将有多个元素需要检查。