Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Maybe the syntax may seem complicated. But it seems to me that the code is read simply:

REM Remove all shapes from all sheets of current workbook
Sub clearGraphs
Dim oDrawPages As Variant   ' All pages of current workbook
Dim oDrawPage As Variant    ' One (next) draw page
Dim oShape As Variant       ' One graph object
Dim i As Long, j As Long    ' Indexes for cycles
    oDrawPages = ThisComponent.getDrawPages()
    If oDrawPages.hasElements() Then
        For i = 0 To oDrawPages.getCount() - 1  ' For all drawpages in workbook
            oDrawPage = oDrawPages.getByIndex(i)
            If oDrawPage.hasElements() Then
REM This For...Next - by descending: after removing object all indexes will be shifting
                For j = (oDrawPage.getCount() - 1) To 0 Step -1
                    oShape = oDrawPage.getByIndex(j)
                    oDrawPage.remove(oShape)
                Next j
            EndIf
        Next i
    EndIf
End Sub

Maybe the syntax may seem complicated. But it seems to me that the code is read simply:

REM Remove all shapes from all sheets of current workbook
Sub clearGraphs
Dim oDrawPages As Variant   ' All pages of current workbook
Dim oDrawPage As Variant    ' One (next) draw page
Dim oShape As Variant       ' One graph object
Dim i As Long, j As Long    ' Indexes for cycles
    oDrawPages = ThisComponent.getDrawPages()
    If oDrawPages.hasElements() Then
        For i = 0 To oDrawPages.getCount() - 1  ' For all drawpages in workbook
            oDrawPage = oDrawPages.getByIndex(i)
            If oDrawPage.hasElements() Then
REM This For...Next - by descending: after removing object all indexes will be shifting
                For j = (oDrawPage.getCount() - 1) To 0 Step -1
                    oShape = oDrawPage.getByIndex(j)
REM Here may be a check any  properties of  object's oShape If (oShape. ..) Then
                    oDrawPage.remove(oShape)
                Next j
            EndIf
        Next i
    EndIf
End Sub
click to hide/show revision 3
make comments have syntax-highlighting

Maybe the syntax may seem complicated. But it seems to me that the code is read simply:

REM # Remove all shapes from all sheets of current workbook
Sub clearGraphs
Dim oDrawPages As Variant   ' REM # All pages of current workbook
Dim oDrawPage As Variant    ' REM # One (next) draw page
Dim oShape As Variant       ' REM # One graph object
Dim i As Long, j As Long    ' REM # Indexes for cycles
    oDrawPages = ThisComponent.getDrawPages()
    If oDrawPages.hasElements() Then
        For i = 0 To oDrawPages.getCount() - 1  ' REM # For all drawpages in workbook
            oDrawPage = oDrawPages.getByIndex(i)
            If oDrawPage.hasElements() Then
REM # This For...Next - by descending: after removing object all indexes will be shifting
                For j = (oDrawPage.getCount() - 1) To 0 Step -1
                    oShape = oDrawPage.getByIndex(j)
REM # Here may be a check any  properties of  object's oShape oShape
                If (oShape. ..) Then
                    oDrawPage.remove(oShape)
                Next j
            EndIf
        Next i
    EndIf
End Sub