Word macro: change one highlight colour to something else
Thread poster: Samuel Murray
Samuel Murray
Samuel Murray  Identity Verified
Netherlands
Local time: 00:54
Member (2006)
English to Afrikaans
+ ...
Feb 23

Hello everyone

I have a file with some text highlighted yellow and some text highlighted red. I want to change the red highlighted text to green highlighted. Do you know of a macro that can do that?

Thanks
Samuel


 
Aurélien ARPAZ
Aurélien ARPAZ
Local time: 00:54
German to French
+ ...
A macro Feb 23

Hello Samuel,

This macro should do what expected:

Sub SwitchHighlightsColor()
Dim r As Range
Set r = ActiveDocument.Range

With r.Find
.Highlight = True
.Forward = True
Do While .Execute(FindText:="", Forward:=True) = True
If r.HighlightColorIndex = wdRed Then
r.HighlightColorIndex = wdGreen
r.Collapse 0
End If
... See more
Hello Samuel,

This macro should do what expected:

Sub SwitchHighlightsColor()
Dim r As Range
Set r = ActiveDocument.Range

With r.Find
.Highlight = True
.Forward = True
Do While .Execute(FindText:="", Forward:=True) = True
If r.HighlightColorIndex = wdRed Then
r.HighlightColorIndex = wdGreen
r.Collapse 0
End If
Loop
End With
End Sub

Hope this helps!

[Modifié le 2024-02-23 08:54 GMT]
Collapse


Samuel Murray
Hans Lenting
 
Hans Lenting
Hans Lenting
Netherlands
Member (2006)
German to Dutch
Yep Feb 23

https://stackoverflow.com/questions/229865/changing-highlighted-text-to-a-different-color

 
Thomas T. Frost
Thomas T. Frost  Identity Verified
Portugal
Local time: 23:54
Danish to English
+ ...
Built-in Feb 23

Click on More to see all options, then Format to specify the formats you want to change and what you want to change them to. You don't need a macro for that.

 
PAS
PAS  Identity Verified
Local time: 00:54
Polish to English
+ ...
Highlighted text Feb 23

@Thomas - AFAIK the "More" -> highlighting option only lets you find highlighted text, but does not distinguish between the highlighting colours, nor does it let you change the highlight colour.

@Samuel - OK, I just tried something and you didn't even need to hold my beer

If you want to change [other] colour to [green], change the highlight icon in the Word ribbon to green.
Go the usual route of expa
... See more
@Thomas - AFAIK the "More" -> highlighting option only lets you find highlighted text, but does not distinguish between the highlighting colours, nor does it let you change the highlight colour.

@Samuel - OK, I just tried something and you didn't even need to hold my beer

If you want to change [other] colour to [green], change the highlight icon in the Word ribbon to green.
Go the usual route of expanding the advanced find/replace.
Choose find highlighted text.
Choose replace with highlighted text.

EDIT
Word will replace any highlighted text to whatever highlight colour you have selected in the ribbon - I just tried it with a couple colours and it seems to work.


[Edited at 2024-02-23 10:04 GMT]

[Edited at 2024-02-23 10:24 GMT]
Collapse


 
Thomas T. Frost
Thomas T. Frost  Identity Verified
Portugal
Local time: 23:54
Danish to English
+ ...
Highlight Feb 23

Yes, it looks like it. Maybe one can define it in a style, but that's a little more complicated. Did anyone ask ChatGPT for a solution?

 
Samuel Murray
Samuel Murray  Identity Verified
Netherlands
Local time: 00:54
Member (2006)
English to Afrikaans
+ ...
TOPIC STARTER
@Hans Feb 23


This one allows me to change all highlights to green, but not only red to green.

Thomas T. Frost wrote:
Click on More to see all options, then Format to specify the formats you want to change and what you want to change them to. You don't need a macro for that.

You can't define the highlight colour when doing find/replace.

[Edited at 2024-02-23 13:47 GMT]


 
Samuel Murray
Samuel Murray  Identity Verified
Netherlands
Local time: 00:54
Member (2006)
English to Afrikaans
+ ...
TOPIC STARTER
@Aurélien Feb 23

Aurélien ARPAZ wrote:
This macro should do what expected: ...

It does, thanks. Unfortunately Word freezes at around 50 pages or so, so it's nice for smaller documents, but didn't do it for one of my files. And... it had tables with tracked changes in it, so I couldn't split and merge the document.


 
Dan Lucas
Dan Lucas  Identity Verified
United Kingdom
Local time: 23:54
Member (2014)
Japanese to English
Updating? Feb 23

Did you turn off screen updating in the VBA script?
If not, put this at the start:

Application.ScreenUpdating = False

And this at the end:

Application.ScreenUpdating = True

Might help.

Regards,
Dan


Hans Lenting
 
Samuel Murray
Samuel Murray  Identity Verified
Netherlands
Local time: 00:54
Member (2006)
English to Afrikaans
+ ...
TOPIC STARTER
@Dan Feb 24

Thanks for the tip.

 
Hans Lenting
Hans Lenting
Netherlands
Member (2006)
German to Dutch
Another idea Feb 24

Samuel Murray wrote:

Thanks for the tip.


And if that doesn't solve it, you could cycle through all paragraphs in the document and use the range object of the paragraphs.

And if that doesn't solve it, you could first cycle thru pars 1 to 200, then from 201 to 400 etc.


 
Aurélien ARPAZ
Aurélien ARPAZ
Local time: 00:54
German to French
+ ...
A clean doc Feb 24

Samuel Murray wrote:

It does, thanks. Unfortunately Word freezes at around 50 pages or so, so it's nice for smaller documents, but didn't do it for one of my files. And... it had tables with tracked changes in it, so I couldn't split and merge the document.


I'm pretty sure it doesn't depend on the size of the document, but on the nature of the document itself. If it's not clean and finalized, it's quite possible that it's stuck somewhere. The only time the macro didn't work for me was when a highlighted text wasn't properly delimited.


 
Stepan Konev
Stepan Konev  Identity Verified
Russian Federation
Local time: 01:54
English to Russian
TransTools (provided that there is no hidden text) Feb 24

If you don't have any text hidden in your file and you have TransTools, you can use the Hide/Unhide Text tool to hide the red highlighted text first.
Then select the green highlighting color in MS Word, press Ctrl+H and replace all hidden text with the same text (leave the 'Replace with' box blank) highlighted in green. This would repaint all your red highlights into green.
Finally, unhide all.
Click to play the gif file below
... See more
If you don't have any text hidden in your file and you have TransTools, you can use the Hide/Unhide Text tool to hide the red highlighted text first.
Then select the green highlighting color in MS Word, press Ctrl+H and replace all hidden text with the same text (leave the 'Replace with' box blank) highlighted in green. This would repaint all your red highlights into green.
Finally, unhide all.
Click to play the gif file below.


[Edited at 2024-02-24 23:28 GMT]
Collapse


 


To report site rules violations or get help, contact a site moderator:


You can also contact site staff by submitting a support request »

Word macro: change one highlight colour to something else






Protemos translation business management system
Create your account in minutes, and start working! 3-month trial for agencies, and free for freelancers!

The system lets you keep client/vendor database, with contacts and rates, manage projects and assign jobs to vendors, issue invoices, track payments, store and manage project files, generate business reports on turnover profit per client/manager etc.

More info »
Wordfast Pro
Translation Memory Software for Any Platform

Exclusive discount for ProZ.com users! Save over 13% when purchasing Wordfast Pro through ProZ.com. Wordfast is the world's #1 provider of platform-independent Translation Memory software. Consistently ranked the most user-friendly and highest value

Buy now! »