You have an ancient version of OO according to your signature. All I can do is go through what to do on my more up to date version as I don't have that old version. It may or may not be the same
Make a copy of your document, close all your others and open that.
Go to Tools menu/Macros/Organise Macros/Openoffice basic
In the dialog that pops up select the name of your document from the left side listbox and click the "New" button.
A popup box will ask you for the name of a module - just click on Okay.
You'll be taken to the macro area for your document where you'll find this:
REM ***** BASIC *****
Sub Main
End Sub
Copy and past the macro code I wrote above in between the sub main and end sub so it looks like this
- Code: Select all Expand viewCollapse view
REM ***** BASIC *****
Sub Main
cs = thiscomponent.stylefamilies.getbyname("CharacterStyles")
ss=thiscomponent.createinstance("com.sun.star.style.CharacterStyle")
ss.charbackcolor = rgb(255,255,20)
cs.insertbyname("CommentStyle",ss)
en =thiscomponent.textfields.createenumeration
tc = thiscomponent.text.createtextcursorbyrange(thiscomponent.text.start)
do until en.hasmoreelements = false
ff= en.nextelement
anch= ff.anchor
tc.gotorange(anch.end,false)
tc.string =ff.textrange.text.string
tc.charstylename = "CommentStyle"
loop
End Sub
When that's done press F5 to run the macro and see if the result is what you want.