View Single Post
 
Old 08-08-2012, 04:47 AM
divakarganta divakarganta is offline Windows Vista Office 2007
Novice
 
Join Date: Aug 2012
Posts: 2
divakarganta is on a distinguished road
Default Apply font color programatically using VBA Word

Hi,
I have code written below, as the code applying color Red to Tick Mark, but the issue is the color Red applying to entire Text entered in Word.
I want the code to be applied to only Tick Mark not the entire text.
Ex: “Th℞is is my test “ in this text ℞ is the Tick Mark and “This” is the text entered in word changed to Red.
Code:
If TextPress Then
ActiveDocument.Characters.Parent
 
'Get current font name and color
FName = selection.Font.Name
fColor = selection.Font.Color
FStrikeThrough = selection.Font.StrikeThrough
FItalic = selection.Font.Italic
'Insert mark
 
selection.Font.Name = FontName
selection.Font.Color = ColorLevel
selection.Font.StrikeThrough = IsStrikethrough
selection.Font.Italic = IsItalic
selection.Font.Name = FontName
selection.TypeText Text:=TM_Chr
 
If FirstTMText = False Then
  For i = 1 To Len(TM_Chr)
    selection.Previous(Unit:=wdCharacter, Count:=1).Select
    selection.Delete
  Next i
 
  selection.Font.Name = FontName
  selection.Font.Color = ColorLevel
  selection.Font.StrikeThrough = IsStrikethrough
  selection.Font.Italic = IsItalic
  selection.Font.Name = FontName
  selection.TypeText Text:=TM_Chr
 
  FirstTMText = True
End If

Last edited by macropod; 08-08-2012 at 05:01 PM. Reason: Added code tags & formatting
Reply With Quote