View Single Post
 
Old 06-12-2017, 08:24 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
If you want to do something with the words already containing the coloured letters then
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
Reply With Quote