Reports.Copy 方法 (Project)
複製自訂報表,並建立具有相同內容的新報表。
語法
運算式。複製 (來源、 NewName)
表達 代表 'Reports' 物件的變數。
參數
名稱 | 必要/選用 | 資料類型 | 描述 |
---|---|---|---|
Source | 必要 | Variant | 要複製之報表的名稱或 報 表物件。 |
NewName | 必要 | String | 新報表的名稱。 |
Source | 必要 | Variant | |
NewName | 必要 | 字串 |
傳回值
Report
新的報表。
範例
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
另請參閱
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。