共用方式為


(專案)

代表專案行事曆中的一年。 Year 物件是 Years 集合的成員。

註解

Project中的 Years 集合開始於 1984 年,結束 2149年中。 在舊版的專案、 排程可以執行從 1984年 2049年。

範例

使用 Year 集合物件

使用 Years ( Index) ,其中 Index 是年度索引號,來回傳單一 Year 物件。 下列範例會計算每個選定資源 2012 年 9 月中的工作天數目。

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: 取得可用年份清單

Years available for project planning

方法

名稱
Default

屬性

名稱
Application
Calendar
數目
Index
名稱
Parent
Shift1
Shift2
Shift3
Shift4
Shift5
Working

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應