#1
|
|||
|
|||
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 |
#2
|
||||
|
||||
Hi divakarganta,
It's not easy to see quite what's going on here without the document & userform that drives the process. Can you attach the document to a post with some representative data (delete anything sensitive)? You do this via the paperclip symbol on the 'Go Advanced' tab.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Apply font color programatically using VBA Word
Quote:
Hi Paul, Please find the attachment, and it has the Word "This is test" and applied the Tick Mark on "test". The test should not change to Tick Mark color. |
#4
|
||||
|
||||
Hi divakarganta,
There is no userform or code in your document (which is a docx file, not a docm file). Without the userform & code that shows how you are making the selection (which shouldn't be necessary anyway - you should be able to define the range), no progress can be made.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Word macro doesn't change font color | Spideriffic | Word VBA | 8 | 11-04-2015 03:47 AM |
Word 2010- help setting automatic font color | Jazz43 | Word | 7 | 09-27-2012 10:59 PM |
Font Color not working in PowerPoint | MrsMoe | PowerPoint | 2 | 12-27-2010 03:42 AM |
Word 2007 Font Color Doesn't Work | nnicko | Word | 2 | 04-16-2010 01:21 PM |
need help with font color | samsongee | Word | 0 | 09-07-2006 10:18 PM |