Shapes Object (Project)

Office 2013 and later

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Represents a collection of Shape objects in a custom report.

Use the Report.Shapes property to get the Shapes collection object. In the following example, the report must be the active view to get the Shapes collection; otherwise, you get a run-time error 424 (Object required) in the For Each oShape In oReport.Shapes statement.

Sub ListShapesInReport()
    Dim oReports As Reports
    Dim oReport As Report
    Dim oShape As shape
    Dim reportName As String
    Dim msg As String
    Dim msgBoxTitle As String
    Dim numShapes As Integer
    numShapes = 0
    msg = ""
    reportName = "Table Tests"
    Set oReports = ActiveProject.Reports
    If oReports.IsPresent(reportName) Then
        ' Make the report the active view.
        Set oReport = oReports(reportName)
        msgBoxTitle = "Shapes in report: '" & oReport.Name & "'"
        For Each oShape In oReport.Shapes
            numShapes = numShapes + 1
            msg = msg & numShapes & ". Shape type: " & CStr(oShape.Type) _
                & ", '" & oShape.Name & "'" & vbCrLf
        Next oShape
        If numShapes > 0 Then
            MsgBox Prompt:=msg, Title:=msgBoxTitle
            MsgBox Prompt:="This report contains no shapes.", _
        End If
         MsgBox Prompt:="The requested report, '" & reportName _
            & "', does not exist.", Title:="Report error"
    End If
End Sub