Application.CreateComparisonReport 方法 (Project)

创建项目两个版本之间的比较报表。

语法

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

表达 返回 Application 对象的表达式。

参数

名称 必需/可选 数据类型 说明
FileName 可选 String 要进行比较的项目文件的完整路径和名称。
TaskTable 可选 String 任务视图中要用于比较的表的名称。
ResourceTable 可选 String 资源视图中要用于比较的表的名称。
Items 可选 PjCompareVersionItems 指定要进行比较的项目的类型。
Columns 可选 PjCompareVersionColumns 指定是仅显示列数据、仅显示列差异,还是同时显示差异和数据。
ShowLegend 可选 Variant 如果 True ,在比较报告中显示图例。

返回值

Boolean

说明

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 支持和反馈,获取有关如何接收支持和提供反馈的指南。