Share via

programmatic (VBA) determination if a task is based on elapsed duration

Anonymous
2012-01-20T23:15:31+00:00

I'm looking for a means (prefereably VBA) to analyze a task and determine if the task's duration is based on an "elapsed" duration.  We have a custom calendar that is defined as 8 work hours per day (8-12, 1-5). we do not use task or resource calendars. periodically we have the need to define a task using the elapsed durations (ed, emo, ew, etc).  We also have a VBA based tool that analyzes schedules for various internal business rules or best practices.  One of these is to display a list of tasks that are defined using the elapsed duration.

Any assistancxe would be appreciated.

ah, yes, we're using Project Server 2007.

Dan

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

John Project 49,710 Reputation points Volunteer Moderator
2012-01-21T16:37:24+00:00

ProjectUser,

Good alternative. So much for my brash statement about not being able to read the value directly. The only thing I would add is:

For Each T In ActiveProject.Tasks

If Not T is Nothing Then

           [your code]

End if

    Next T

This handles blank task lines if they are present.

Or, to eliminate the need to check the "add space before label" option, the following code should work

Sub CheckElapsed()

Dim T As Task

Dim DurationString As String

For Each T In ActiveProject.Tasks

If Not T Is Nothing Then

DurationString = T.GetField(pjTaskDuration)

If InStr(1, DurationString, "es") > 0 Or InStr(1, DurationString, "ee") > 0 Then

T.Text1 = "Not Elapsed"

ElseIf InStr(1, DurationString, "e") > 0 Then

T.Text1 = "Elapsed"

Else

T.Text1 = "Not Elapsed"

End If

End If

Next T

End Sub

John

Was this answer helpful?

0 comments No comments

Answer accepted by question author

Anonymous
2012-01-21T04:00:40+00:00

IMHO, as an alternative, you can try the below code and then filter Text1 field for "Elapsed":

Sub CheckElapsed()

    Dim T As Task

    Dim DurationString As String

    For Each T In ActiveProject.Tasks

           DurationString = T.GetField(pjTaskDuration)

           If Mid(DurationString, InStr(1, DurationString, " ") + 1, 1) = "e" Then

              T.Text1 = "Elapsed"

           Else

              T.Text1 = "Not Elapsed"

           End If

    Next T

End Sub

PS.

  • Just make sure "Add space before label" is checked in Tools | Options | Edit, before testing the macro.
  • Test it on backup copies of mpp files.
  • Modify "e" for your language if it is not English.
  • The last parameter in InStr function is a space character enclosed in double quotes (i.e. Chr(32) ).

Was this answer helpful?

0 comments No comments

5 additional answers

Sort by: Most helpful
  1. John Project 49,710 Reputation points Volunteer Moderator
    2012-01-23T17:16:37+00:00

    Dan,

    If one or more of these responses answered your initial question, then please mark it as answered so it doesn't hang around indefinitely as an open item.

    John

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2012-01-23T17:10:30+00:00

    thanks for the quick responces. we'll try the code.

    Dan

    Was this answer helpful?

    0 comments No comments
  3. John Project 49,710 Reputation points Volunteer Moderator
    2012-01-21T01:49:35+00:00

    dfelgen115,

    I could almost guarantee I've answered this question before but that was a few years back. You can't get the answer by directly reading the Duration field so an indirect approach must be used. Since you've already done some VBA I'll just give you the approach and you can work out the details.

    Use the Application.DateDIfference Method to find the minutes between start and finish. Compare that to a direct reading of the Duration field which will also be in minutes. If both values are the same, the duration is working time. If they are different, the duration is by default, elapsed time.

    Hope this helps.

    John

    Was this answer helpful?

    0 comments No comments