包含 Year 对象的集合。
备注
在Project 年 集合于 1984 年开始,并在 2149年结束。 在以前版本的 Project 中,日程安排可以运行从 1984年到 2049年。
示例
使用 Year 对象
使用 Year ( Index) (其中 Index 是年份索引号)返回单个 Year 对象。 下面的示例对每个选定资源 9 月 2012年的月份中的工作日数进行计数。
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
使用 Years 集合
使用 Years 属性可以返回一个 Years 集合。 以下示例列出活动项目的日历中的所有年份。
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
图 1 显示了 CountYears宏的结果。
图 1. 获取可用年份列表

属性
| 名称 | 
|---|
| Application | 
| Count | 
| 项目 | 
| Parent | 
另请参阅
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。