Neither for a text document nor for a specific style I know a ReferenceCounter
or a Boolean property like IsUsed
concerning styles. (.IsPhysical=False
seemingly doesn’t apply to user styles.) This looks strange to me since there references might be counted internally: Try to delete a used style from the S&F panel, and you will see what I take as an indication. But a recorded macro for the purpose will again not show the alert.
(This despite the fact that reference counting is a general concept of programming.)
Thus: The only way I know to avoid the deletion of a used styles by a macro is to count the references (cases-of-usage) explicitly. Since ParaStyle also is used in TextFrame and TextTable (In tables per cell! Are there more classes?) there can be lots of objects needing to be tested for a specific ParaStyle property this requires some patience during programming and probably also when the code is running for a large document. (For character styles it can be much worse.) In case of deeper interest read OOME Chapter 13.12. by Andrew Pitonyak. (I don’t think there were changed relevant thing so far since.)
To simply delete a paragraph style without any checks you can use this code:
Sub deleteParaStyle(Optional pParaStyleName As String) REM Optuonal only for the demo!
REM There are no checks implemented! You can analyse the parameter, of course.
REM Paragraphs set to a deleted style fall back to its parent style.
REM === Only for the demo again
If IsMissing(pParaStyleName) Then pParaStyleName = "psVariant1"
REM === End=== Comes actually working part.
doc0 = ThisComponent
styleFamilies = doc0.StyleFamilies
paraStyles = styleFamilies.getByName("ParagraphStyles")
REM isonParaStyle = paraStyles.GetByName(pParaStyleName) REM Only for inspection.
paraStyles.RemoveByName(pParaStyleName)
End Sub