I have a macro to change text within, and including, square brackets to RED, Arial, as shown below
RDescrip = ThisComponent.createReplaceDescriptor
RDescrip.searchRegularExpression = True
RDescrip.searchString = "\[([^\]]*)\]"
rngs = ThisComponent.findAll(RDescrip)
for i = 0 to rngs.count-1
foundText = rngs.getByIndex(i)
foundText.CharColor = RGB(255,0,0)
foundText.CharFontName = "Arial"
foundText.CharHeight = 14
foundText.CharWeight = 150
next i
I would now like to add a second macro to change text within conventional brackets i.e. () to Brown text (255,160,0)... but I don't know how to change this line to do so
RDescrip.searchString = "\[([^\]]*)\]"
Can anybody help me please?
[Solved] Writer macro to change text colour inside brackets
[Solved] Writer macro to change text colour inside brackets
Last edited by MrProgrammer on Tue Aug 09, 2022 3:52 pm, edited 1 time in total.
Reason: Tagged ✓ [Solved] -- MrProgrammer, forum moderator
Reason: Tagged ✓ [Solved] -- MrProgrammer, forum moderator
parking
Open Office 4.0.1 on Windows 7
Open Office 4.0.1 on Windows 7
Re: writer macro to change text colour inside brackets
Hallo
Instead Direct-Formattting you should assign a CharStyle with these Attributes
Code: Select all
RDescrip.searchString = "\(([^()]*)\)"
Code: Select all
FoundText.CharStyleName = your_charstyle_with_red_bold_arial
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 7.6 flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
- MrProgrammer
- Moderator
- Posts: 4905
- Joined: Fri Jun 04, 2010 7:57 pm
- Location: Wisconsin, USA
Re: Writer macro to change text colour inside brackets
Your question suggests that you do not understand regular expressions. Basic information is in Regular Expressions in Writer. You also need to understand styles. These are very important features of OpenOffice which will aid you in using the full capabilities of the program.
Once you understand regular expressions and styles, you don't need others to write macros for you to perform the tasks you've asked about. You can record a macro yourself. You don't need to understand any programming to record macros. You need to create character styles, say Brackets and Parens, to set the colors you want for the text. Then the steps you record are:
• Edit → Find and Replace → More options → Check Regular Expressions → Uncheck Current Selection Only
→ Search for → \[[^]]+\] → Find All
• Format → Styles and Formatting → Character Styles (second icon) → Double-click Brackets
• Edit → Find and Replace → More options → Check Regular Expressions → Uncheck Current Selection Only
→ Search for → \([^)]+\) → Find All
• Format → Styles and Formatting → Character Styles (second icon) → Double-click Parens
• Stop recording, then assign a name for your macro
You can record one macro to perform both tasks, or you can have separate macros for brackets and parentheses.
If this solved your problem please go to your first post use the Edit button and add [Solved] to the start of the subject field. Select the green checkmark icon at the same time.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.6.3, iMac Intel. The locale for any menus or Calc formulas in my posts is English (USA).
AOO 4.1.7 Build 9800, MacOS 13.6.3, iMac Intel. The locale for any menus or Calc formulas in my posts is English (USA).
Re: Writer macro to change text colour inside brackets
Thank you both for your help. I will investigate this evening. You are correct, I don't understand enough about what I am doing, but I'm also not using this activity enough to spend many hours learning . I did hope I would get a simple rearrangement of the expression I sent, but it seems I may have to get into it a bit more.
Thank you again
Thank you again
parking
Open Office 4.0.1 on Windows 7
Open Office 4.0.1 on Windows 7