This macro is a partial solution. It seems to work nicely if the document has only “paragraphs” (if there are tables, it does not reach the end of the document):
Sub RemoveAllDirectParagraphFormats
Dim oDoc, oFrame, dispatcher As Object
Dim oVC, oCurs As Object
Dim sStyleNamePart As String
oDoc = ThisComponent
oFrame = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
oVC = oDoc.CurrentController.getViewCursor()
oVC.gotoStart(False)
oCurs = oVC.getText().createTextCursorByRange(oVC)
rem Remove direct paragraph formats from first paragraph:
dispatcher.executeDispatch(oFrame, ".uno:ResetAttributes", "", 0, Array())
rem Move to next paragraph and repeat until end of document:
While oCurs.gotoNextParagraph(False)
dispatcher.executeDispatch(oFrame, ".uno:GoToNextPara", "", 0, Array())
dispatcher.executeDispatch(oFrame, ".uno:ResetAttributes", "", 0, Array())
Wend
End Sub
I adapted it from LibreOffice: stop macro loop at end of file - Super User (macro by Jim K, User Jim K - Super User), but I don’t have enough reputation to comment there. I basically took his macro and replaced the commands inside the loop by “ResetAttributes” and “MoveToNextParagraph”.
If someone could alter it so that it also works with documents with tables, it would be great. It could treat each table cell as a paragraph and remove its direct formatting. I have tried for some hours and could not make it work, but it can’t be too difficult for someone versed in macros.