Share via


ReportTable オブジェクト (Project)

プロジェクト レポート内のテーブル、フォーム内の図形を表します。

注釈

注:

[!メモ] マクロの記録を ReportTableオブジェクトには実装されていません。 Projectでマクロを記録し、レポート テーブルを手動で追加するかテーブル要素を編集、追加して、レポート テーブルを操作するための手順は記録されません。

ReportTable オブジェクトは Shape オブジェクトの一種です。Table オブジェクトには関係ありません。 Project では、レポート テーブルに対する VBA のサポートが制限されています。テーブル フィールドを指定するには、[ フィールド リスト ] 作業ウィンドウを手動で使用します (図 1 を参照)。 [フィールド リスト] 作業ウィンドウを表示または非表示にするには、リボンの [テーブル ツール] の [デザイン] タブで [テーブル データ] コマンドを選択します。 テーブル レイアウトまたはデザイン プロパティを指定するには、リボンの [ デザイン ] タブと [ レイアウト ] タブを使用します。

UpdateTableData メソッドを使用して、レポートのテーブルに関連付けられているデータのクエリを更新することができます。 テーブルのセルにテキストを取得するには、 GetCellText メソッドを使用します。

プログラムによって ReportTable を作成するには、Shapes.AddTable メソッドを使用します。 ReportTable オブジェクトを返すには、 を使用Shapes(Index).Tableします。ここで、Index は図形の名前またはインデックス番号です。

TestReportTableマクロは、という名前のテーブルのテスト、レポートを作成し、 ReportTableオブジェクトが作成されます。

Sub TestReportTable()
    Dim theReport As Report
    Dim theShape As Shape
    Dim theReportTable As ReportTable
    Dim reportName As String
    Dim tableName As String
    Dim rows As Integer, columns As Integer, left As Integer, _
        top As Integer, width As Integer, height As Integer    
    rows = 3
    columns = 4
    left = 20
    top = 20
    width = 200
    height = 100
    
    reportName = "Table Tests"
    tableName = "Basic Project Data Table"
    
    Set theReport = ActiveProject.Reports.Add(reportName)
    
    ' Project ignores the NumRows and NumColumns parameters when creating a ReportTable.
    Set theShape = theReport.Shapes.AddTable( _
        rows, columns, left, top, width, height)
    
    theShape.Name = tableName
    
    Set theReportTable = theShape.Table
    
    With theReportTable
        Debug.Print "Rows: " & .RowsCount
        Debug.Print "Columns: " & .ColumnsCount
        Debug.Print "Table contents:" & vbCrLf & .GetCellText(1, 1)
    End With
End Sub

図 1 は、 TestReportTableマクロで表テスト レポートの一番上の ReportTableオブジェクトを作成します。 1 つの行と 1 つの列があるテーブルを初めて作成する場合 NumRowsNumColumnsAddTableメソッドのパラメーターは、影響を与えるありません。 テーブル内の行と列の数は、[フィールド リスト ] 作業ウィンドウからテーブルにフィールドを手動で追加するとき、または UpdateTableData メソッドを使用すると更新されます。 行の数を制限するフィールドをフィルター処理できます。 TestReportTableマクロは、VBE のイミディ エイト ウィンドウで以下を書き込みます。

Rows: 1
Columns: 1
Table contents:
Use the Table Data taskpane to build a table

図 1 の下の ReportTableオブジェクトは、 レポート ツールの [ デザイン] タブで テーブルを選択すると、プロジェクトが作成される既定のレポートのテーブルです。 プロジェクト名を表示して、プロジェクトのサマリー タスクの開始日、終了日、および % を完了 (タスク ID = 0)。

図 1. ReportTable オブジェクトには、フィールドを追加して書式設定を変更するための手動編集が必要です

ReportTable オブジェクトには手動編集が必要ですReportTable オブジェクトを削除するには、次のマクロのように Shape.Delete メソッドを使用します。

Sub DeleteTheReportTable()
    Dim theReport As Report
    Dim theShape As Shape
    Dim reportName As String
    Dim tableName As String
    
    reportName = "Table Tests"
    tableName = "Basic Project Data Table"
    
    Set theReport = ActiveProject.Reports(reportName)
    Set theShape = theReport.Shapes(tableName)
    
    theShape.Delete
End Sub

レポート全体を削除するのには次のように、別のビューに変更します。

Sub DeleteTheReport()
    Dim i As Integer
    Dim reportName As String
    
    reportName = "Table Tests"
    
    ' To delete the active report, change to another view.
    ViewApplyEx Name:="&Gantt Chart"
    
    ActiveProject.Reports(reportName).Delete
End Sub

メソッド

名前
GetCellText
UpdateTableData

プロパティ

名前
ColumnsCount
RowsCount

関連項目

レポート オブジェクト

Shape オブジェクト

グラフ オブジェクト

Chart.DataTable プロパティ

サポートとフィードバック

Office VBA またはこの説明書に関するご質問やフィードバックがありますか? サポートの受け方およびフィードバックをお寄せいただく方法のガイダンスについては、Office VBA のサポートおよびフィードバックを参照してください。