Reports.Copy 方法 (Project)

复制自定义报表并创建具有相同内容的新报表。

语法

表达式复制 (NewName)

表达 一个代表“Reports”对象的变量。

参数

名称 必需/可选 数据类型 说明
Source 必需 Variant 要复制的报表 的名称或 Report 对象。
NewName 必需 字符串 新报表的名称。
Source 必需 Variant
NewName 必需 字符串

返回值

报告

新报表。

示例

CopyAReport 宏检查要复制的指定报表是否存在,并检查新报表是否已存在。 然后,该宏使用 Source 参数的变体之一来创建报表的副本,然后显示新报表。

Sub CopyAReport()
    Dim reportName As String
    Dim newReportName As String
    Dim newExists As Boolean
    Dim oldExists As Boolean
    Dim report2Copy As Report
    Dim newReport As Report
    
    reportName = "Table Tests"
    newReportName = "New Table Tests"
    oldExists = ActiveProject.Reports.IsPresent(reportName)
    newExists = ActiveProject.Reports.IsPresent(newReportName)
    
    Debug.Print "oldExists " & CStr(oldExists) & "; newExists " & newExists
    
    If oldExists And Not newExists Then
        Set report2Copy = ActiveProject.Reports(reportName)
        
        ' Use either of the following two statements.
        'Set newReport = ActiveProject.Reports.Copy(report2Copy, newReportName)
        Set newReport = ActiveProject.Reports.Copy(reportName, newReportName)
       
        newReport.Apply
    End If
    
    If (oldExists = False) Then
         MsgBox Prompt:="The requested report to copy, '" & reportName _
            & "', does not exist.", Title:="Report copy error"
    ElseIf newExists Then
        MsgBox Prompt:="The new report '" & newReportName _
            & "' already exists.", Title:="Report copy error"
    Else
        MsgBox Prompt:="The new report '" & newReportName & "'" _
            & vbCrLf & "is copied from '" & reportName & "'.", _
            Title:="Report copy success"
    End If
End Sub

另请参阅

Reports 对象Report 对象

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。