To make a macro that selects specific chars in a text and colour them

Hello, friends.

I need to change the color to every ‘a’ and every ‘2’ characters in a text. ‘A’ should be red and ‘2’ should be green. Looking in the internet I found out this can be done with a macro. Since I am not a programmer I need the code to paste it in my main module library (I have found already how to create and when I have to write the code, but not a clue on what code should it be)

Thank you in advance

Unless this is done to get acquainted with LO macros, you can do without.


First begin by creating character styles for the result: one for “a” and one for “2”.


Use Edit>Find & Replace with a Find target of “a” (second iteration will be with “2”). Press Find All and close the dialog. All occurrences remains selected. Apply the character style from the side style pane with a double-click.

Do the same for the other target.

3 Likes

Looking at the dialogue for search&replace I guess you can do this without, as you can exchange attributes directly.

Also it is possible to use search only for find-all, so everything is selected, then you can change the style of all selected objects.

So do you really need a macro? Or was this an assumption, based on “sources from the internet”.

(Ok - I see I’m to slow at typing…)

Thank you @ajlittoz, I see how to do it and it is enough for me.

Thanks to @Wanderer too, best wishes.