Table of contents
TOC
Collapse the table of content
Expand the table of content

Years Object (Project)

office 365 dev account|Last Updated: 6/12/2017
|
1 Contributor

Contains a collection of Year objects.

Remarks

The Years collection in Project begins in 1984 and ends in 2149. In previous versions of Project, scheduling can run from 1984 to 2049.

Examples

Using the Year Object

Use Years ( Index), where Index is the year index number, to return a single Year object. The following example counts the number of working days in the month of September 2012 for each selected resource.

Dim r As Resource
Dim d As Integer
Dim workingDays As Integer
Dim theMonth As PjMonth

theMonth = pjSeptember

For Each r In ActiveSelection.Resources()
    workingDays = 0
    With r.Calendar.Years(2012).Months(theMonth)
        For d = 1 To .Days.Count
            If .Days(d).Working = True Then
                workingDays = workingDays + 1
            End If
        Next d
    End With
    MsgBox "There are " & workingDays & " working days in " _
        & r.Name & "'s calendar for month " & theMonth
Next r

Using the Years Collection

Use the Years property to return a Years collection. The following example lists all the years in the calendar of the active project.

Sub CountYears()
    Dim c As Long
    Dim temp As String

    For c = 1 To ActiveProject.Calendar.Years.Count
        temp = temp & ListSeparator & " " & _
            ActiveProject.Calendar.Years(c + 1983).Name
    Next c

    MsgBox Right$(temp, Len(temp) - Len(ListSeparator & " "))
End Sub

Figure 1 shows the results of the CountYears macro.

Figure 1. Getting the list of years available

Years available for project planning

Properties

Name
Application
Count
Item
Parent

See also

Other resources

Project Object Model

© 2017 Microsoft