![]() |
#1
|
|||
|
|||
![]()
Good Evening All,
I have a question that I hope someone can help me with. ![]() I'd like to perform a find & replace of sorts. I'd like to find the words directly before commas and change the colour of them in a whole document, e.g. Original Text: This is line, number one in word. This is line number, two in word. This is line number three in, word. Desired Result: This is line, number one in word. This is line number, two in word. This is line number three in, word. I don't mind if the comma also changes colour as it will be removed after. I've looked around online but couldn't really find anything that would get me started or at least point me in the right direction. Any help on this would me much appreciated. Thanks in advance, Harvi |
#2
|
||||
|
||||
![]()
The following should work for you
Code:
Sub Macro1() Dim oRng As Range Set oRng = ActiveDocument.Range With oRng.Find Do While .Execute(findText:=",") oRng.MoveStartUntil Chr(32), wdBackward oRng.Font.ColorIndex = wdRed oRng.Collapse 0 Loop End With Set oRng = Nothing End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
![]()
Hi Gmayor
Thank you for getting back to me. The code you provided has worked perfectly. Thank you so much for this, it has helped me a lot in my project. Take care, |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
VBA Marco to change font colour of every other word | Harvi007 | Word VBA | 2 | 08-05-2022 02:01 PM |
![]() |
knpaddac | Word VBA | 3 | 03-15-2021 03:00 PM |
![]() |
RealmOfCOnfusion | Outlook | 1 | 06-30-2016 09:55 PM |
Change single character in PPT to another font macro | rtwwpad | PowerPoint | 1 | 01-19-2013 05:08 PM |
![]() |
meileetan | Project | 3 | 09-12-2012 07:09 AM |