Year Object (Project)
Represents a year in a project calendar. The Year object is a member of the Years collection.
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.