![]() |
|
#1
|
|||
|
|||
|
Hi
I want to change the color of a specific letter in the word in my document then after select that word, with run a macro, all of similar words in my document be like that word. I attach an example. Thanks for your help |
|
#2
|
||||
|
||||
|
If you want to colour the letters in the two words as shown, then
Code:
Sub Macro1()
'Graham Mayor - http://www.gmayor.com - Last updated - 13 Jun 2017
Const sFind As String = "posting|question"
Dim vFind As Variant
Dim oRng As Range
Dim i As Integer
vFind = Split(sFind, "|")
For i = 0 To UBound(vFind)
Set oRng = ActiveDocument.Range
With oRng.Find
Do While .Execute(FindText:=vFind(i))
Select Case i
Case Is = 0
oRng.Start = oRng.Start + 2
Case Is = 1
oRng.Start = oRng.Start + 3
End Select
oRng.End = oRng.Start + 2
oRng.Font.ColorIndex = wdRed
oRng.Collapse 0
Loop
End With
Next i
End Sub
Code:
Sub Macro2()
'Graham Mayor - http://www.gmayor.com - Last updated - 13 Jun 2017
Dim oRng As Range
Const strList As String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
Set oRng = ActiveDocument.Range
With oRng.Find
.Font.ColorIndex = wdRed
Do While .Execute
oRng.MoveEndWhile strList
oRng.MoveStartWhile strList, wdBackward
'do something with the word e.g.
oRng.Font.ColorIndex = wdBlue
'end of word process
oRng.Collapse 0
Loop
End With
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
| Tags |
| change color of a letter, run a macro, similar words |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Directory Mail Merge Letter Format Problem
|
slunkc | Mail Merge | 3 | 03-21-2017 11:16 AM |
| Converting Word to PDF, page count increases by 11 due to format change | sirupwaffel | Word | 0 | 01-19-2017 09:30 AM |
Converting letter format documents to A4 format
|
TJB | Word | 1 | 06-01-2016 06:35 AM |
| Change from General Format to number format | gbaker | Excel | 3 | 08-16-2013 01:04 PM |
| if letter change font also change | gsrikanth | Excel | 1 | 05-15-2012 03:03 AM |