Macros and deleting

I’m attempting to delete a series of shapes, on a Calc spreadsheet, with a macro. Is there an easy way to program this in the Basic IDE? I think I’ve found a few possibilities but I’m having a hard time wrapping my head around the syntax being used.

Thanks!

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
				If (oShape. ..) Then
 					oDrawPage.remove(oShape)
				Next j
			EndIf
		Next i
	EndIf
End Sub

I am only beginning to understand drawpage but try ignoring ThisComponent.getDrawPages() instead, cycle through each sheet. Then grab it’s drawpage and cycle through it’s shapes. I think that there is only zero or one drawpage per sheet. aside: The guy that taught me programming (many years ago) never trusted functionality that a language’s compiler didn’t use. I am inclined to apply the same principle to libreoffice. I think that in use, the developers will regularly refer to the getDrawPage on a sheet, but they might never use getDrawPages() in the product at all.

The easiest way is to use macro recording. To enable the feature, go to ToolsOptionsLibreOfficeGeneral and check “Enable experimental (unstable) features”. A new entry “Record Macro” will appear in ToolsMacros. Once you click on it, macro recording mode will start and almost everything (for more on this topic and the list of actions that are not recorded read Recording a Macro) you do while in it will be saved once you click “Stop Recording” button. You will then be asked to save newly created macro, given the choice of storing it only for the current document or being generally accessible.

If you are interested in seeing the code generated this way, open ToolsMacrosOrganize MacrosLibreOffice Basic, select macro and click “Edit”.

the macro recorder isn’t all that much use in this case. At best it provides a very clunky workaround method to what should be a simple identify as object and delete loop. Only, I don’t know how to code that loop with the unfamiliar libreoffice structures