Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-12-2017, 01:26 PM
GR_mahdi GR_mahdi is offline Change Letter Format in Word Windows 10 Change Letter Format in Word Office 2016
Novice
Change Letter Format in Word
 
Join Date: Jun 2017
Posts: 1
GR_mahdi is on a distinguished road
Default Change Letter Format in Word

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
Attached Images
File Type: jpg similar.jpg (136.7 KB, 11 views)
Reply With Quote
  #2  
Old 06-12-2017, 08:24 PM
gmayor's Avatar
gmayor gmayor is offline Change Letter Format in Word Windows 10 Change Letter Format in Word Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
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 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
Reply

Tags
change color of a letter, run a macro, similar words



Similar Threads
Thread Thread Starter Forum Replies Last Post
Change Letter Format in Word 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
Change Letter Format in Word 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

Other Forums: Access Forums

All times are GMT -7. The time now is 07:44 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft