Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
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
  #2  
Old 08-08-2012, 05:11 PM
macropod's Avatar
macropod macropod is online now Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 16,647
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

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
[MS MVP - Word]
Reply With Quote
  #3  
Old 08-08-2012, 07:30 PM
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

Quote:
Originally Posted by macropod View Post
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.


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.
Attached Files
File Type: docx This is test.docx (11.5 KB, 5 views)
Reply With Quote
  #4  
Old 08-08-2012, 08:05 PM
macropod's Avatar
macropod macropod is online now Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 16,647
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

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
[MS MVP - Word]
Reply With Quote
Reply

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


All times are GMT -7. The time now is 10:39 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft