共用方式為


Project) (Application.CreateComparisonReport 方法

會在兩個專案版本之間建立比較報表。

語法

expressionCreateComparisonReport( _FileName_, _TaskTable_, _ResourceTable_, _Items_, _Columns_, _ShowLegend_ )

表達 會傳回 Application 物件的運算式。

參數

名稱 必要/選用 資料類型 描述
FileName 選用 字串 要比較之專案檔案的完整路徑和名稱。
TaskTable 選用 字串 要在任務檢視中進行比較之表格的名稱。
ResourceTable 選用 字串 要在資源檢視中進行比較之表格的名稱。
Items 選用 PjCompareVersionItems 會指定要比較之項目的類型。
Columns 選用 PjCompareVersionColumns 會指定是否僅顯示欄資料,僅顯示欄差異,或顯示差異及資料兩者。
ShowLegend 選用 變數 如果 為 True ,比較報表中顯示圖例。

傳回值

布林值

註解

CreateComparisonReport 方法會比較任務或資源資訊,但沒有工作分派資訊。

範例

下列範例會示範如何建立比較報表。 程式碼首先會檢查專案目前是否已開啟,然後檢查任務或資源是否在該專案中。 比較報表是以成本表格為基礎,會篩選出有變更的任務或資源成本資訊,並顯示任務或資源之差異的欄。 最後,比較報表會根據目前 (第一個) 專案的檔案名稱儲存。

Sub ComparisonReport () 
    If Projects.Count = 0 Then 
        MsgBox "You must have at least one active project open before you can compare projects.", _ 
            vbInformation 
        Exit Sub 
    ElseIf ActiveProject.Tasks.Count = 0 Then 
        If ActiveProject.ResourceCount = 0 Then 
            MsgBox "There are no task or resources in the current project. " & vbCrLf _ 
            & "Open a project with either tasks or resources before creating a comparison report.", _ 
            vbInformation 
            Exit Sub 
        End If 
    End If 
 
    ' Get the name of the project to use for saving the comparison report. 
    Dim currentProject As Project 
    Set currentProject = ActiveProject 
 
    Dim previousVersion As String 
    previousVersion = "[full path to .mpp file to compare with the active project.]" 
 
    CreateComparisonReport FileName:=previousVersion, _ 
    TaskTable:="Cost", _ 
    ResourceTable:="Cost", _ 
    Items:=pjCompareVersionItemsChangedItems, _ 
    Columns:=pjCompareVersionColumnsDifferencesOnly, _ 
    Showlegend:=True 
 
    ' Save the comparison report based upon the name of the first project. 
    Dim comparisonReport As Project 
    Set comparisonReport = ActiveProject 
    ActiveProject.SaveAs currentProject & "_Compared.mpp" 
End Sub

支援和意見反應

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