Macro to find bold text and apply a character style [closed]

asked 2019-02-05 04:58:37 +0200

DDorin gravatar image

updated 2019-02-05 13:12:24 +0200

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
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by DDorin
close date 2019-02-06 04:41:41.000396


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

arnowa gravatar imagearnowa ( 2019-08-19 14:11:40 +0200 )edit