Year object (Project)
Represents a year in a project calendar. The Year object is a member of the Years collection.
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
Methods
Name |
---|
Default |
Properties
Name |
---|
Application |
Calendar |
Count |
Index |
Months |
Name |
Parent |
Shift1 |
Shift2 |
Shift3 |
Shift4 |
Shift5 |
Working |
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.