Macro to find bold text and apply a character style

I found this macro, but it just replaces the found text by an unformatted string. How can I modify this code to apply to this text a character style?

Sub FindReplaace
'The purpose of this macro is to surround all BOLD elements with {{ }} and change the Bold attribute to NORMAL
'This uses regular expressions.
Dim oDoc, oReplace  As Object
Dim SrchAttributes(0) As New
Dim ReplAttributes(0) As New
oDoc = ThisComponent
oReplace = oDoc.createReplaceDescriptor

'Regular expression. Match any text
oReplace.SearchString = ".*"
'Note the & places the found text back
oReplace.ReplaceString = "{{ & }}"
oReplace.SearchRegularExpression=True 'Use regular expressions
oReplace.searchAll=True 'Do the entire document

REM This is the attribute to find
SrchAttributes(0).Name = "CharWeight"

REM This is the attribute to replace it with
ReplAttributes(0).Name = "CharWeight"
REM Set the attributes in the replace descriptor

REM Now do the work!

End Sub

I am even urgently interested in an answer to this question! Why is it flagged “irrelevant”?

1 Like