Macros/General/004/en

Description
The macro presented here is intended to show how to remove unused custom styles from a document.

The macro starts by accessing the "style families". Depending on the type of document these can be CharacterStyles, ParagraphStyles, FrameStyles, PageStyles, NumberingStyles, CellStyles, ShapeStyles.

The code below searches through the cell styles of a Calc sheet, in which the CellStyles collection is looped through. For each element, the methods isUserDefined and isInUse are used to test if it is a custom style used or not.

The only particularity is that we browse the collection "backwards" from n to zero to avoid problems (since we delete elements from the browsed collection).

Code
In LibreOffice Basic: