使用TimeScale识别在MS Project中过度分配的特定资源

问题描述 投票:1回答:2

我有多个资源(学习者,辅导员和房间)分配给任务(培训课程),我想确定哪些是双重预订,然后将它们添加到文本列。

我正在使用TimeScale方法,我目前正在尝试计算双重预订,假设任何资源的时间超过在该会话的给定开始和结束日期分配给它们的会话长度必须是双重预订。

但是,我无法确定如何确定分配的总时间。 pjTimeScale属性似乎没有返回我需要的东西。使用pjTimescaleHours最接近应返回的实际值。

我错过了什么?还是有更好的方法?

Sub Overallocations()
'T.Text19 is the Overallocation column
'Identify the overallocations and the source ID
Dim T As Task
Dim R As Resource
Dim tsvs As TimeScaleValues

Dim asn As Assignment

For Each T In ActiveProject.Tasks
T.Text19 = ""
Next T

'Start the allocation of Rooms process
For Each T In ActiveProject.Tasks

i = 0

Application.StatusBar = "Checking Session No." & T.ID
'Checks to see if the task is a valid Module session and if it has been 
confirmed. Skips if not a session or if its a confirmed session
If Left(T.Name, 1) <> "M" Then
    GoTo SkipT
End If

For Each R In T.Resources

    Set tsvs = R.TimeScaleData(T.Start, T.Finish, pjResourceTimescaledWork, 
pjTimescaleHours)
    Duration = (T.Finish - T.Start) * 60 * 24


    If tsvs(1).Value > Duration + 1 Then  'THIS IS WHAT IS NOT WORKING
        If T.Text19 = "" Then
            T.Text19 = R.Name
        Else
            T.Text19 = T.Text19 & ", " & R.Name
        End If
    End If
Next R

SkipT:
Next T 'Next Task

MsgBox "The identification of overallocation has been completed.", 
vbInformation, "Resource Overallocation Complete"

End Sub
vba ms-project
2个回答
0
投票

我有多个资源(学习者,辅导员和房间)分配给任务(培训课程),我想确定哪些是双重预订......

换句话说,需要识别分配给重叠训练课程的学习者,辅导员和房间。

虽然这可以使用TimeScaleData方法完成,但更容易的方法是查找重叠会话。培训课程重叠有四种情况:

  • B类在A类之前开始并且在A类仍在运行时结束。
  • B类在A类运行时启动,在A类后完成。
  • 当A类运行时,B类开始并结束。
  • B级在A级之前开始,在A级之后结束。

所有四种情景都可以用一个共同的表达式来识别:Class B starts before Class A ends and Class B ends after Class A starts;见下图。

graphical explanation of how two time frames can overlap (or not)

以下是适用于此方法的代码:

Sub IdentifyOverlappingAssignments()

Dim T As Task
Dim R As Resource

For Each T In ActiveProject.Tasks

    Application.StatusBar = "Checking Session No." & T.ID

    T.Text19 = vbNullString

    'Checks to see if the task is a valid Module session and if it has been confirmed.
    If Left(T.Name, 1) = "M" Then

        For Each R In T.Resources

            ' check to see if this resource is assigned to another task
            ' at all during the duration of this task
            Dim asn As Assignment
            For Each asn In R.Assignments
                If asn.Task.UniqueID <> T.UniqueID Then
                    ' do the tasks overlap?
                    If asn.Task.Finish > T.Start And asn.Task.Start < T.Finish Then
                        If T.Text19 = "" Then
                            T.Text19 = R.Name & " (" & asn.Task.ID & ")"
                        Else
                            T.Text19 = T.Text19 & ", " & R.Name & " (" & asn.Task.ID & ")"
                        End If
                    End If
                End If
            Next asn

        Next R
    End If
Next T

MsgBox "The identification of overallocation has been completed." _
    , vbInformation, "Resource Overallocation Complete"

End Sub

注意:在这种情况下使用TimeScaleData存在问题,原因有多种,包括:1)资源可以按50%的使用率分配,并且不会被识别为双重预订,因为不会被分配,2)如果课程在半小时开始(例如,上午10:30 - 下午12:00),您需要将时间刻度值缩小到分钟,因为使用pjTimescaleHours将返回整个小时(例如,时间刻度值将从上午10:00开始),这很容易将错误介绍给您的代码。


0
投票

两件事,一个关于代码的指针和一个问题。

  1. 如果你是...为了通过任务集合进行连接,记得放一个If ..然后就像在这里一样抓住空行。 PM喜欢空行,他们会错误你的代码。我也是为资源做的,因为有时它们也会在那里放空行。
  2. 我可以问你为什么要这样做,而不是使用Project中内置的'Overallocated'功能?如果资源在任何给定的小时内分配了超过1小时的工作,那么该资源将自动标记为分配给它们的任何任务。这是很酷的代码,但除非我遗漏了什么,否则应该是不必要的。

码:

Sub Foo()
Dim T As Task
Dim R As Resource
    For Each T In ActiveProject.Tasks
        If Not (T Is Nothing) Then
            'Task stuff
            For Each R In T.Resources
                If Not (R Is Nothing) Then
                    Resource Stuff
                End If
            Next R
        End If
    Next T
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.