MS Word: How to get a macro to change text in custom color?
-
Everyday, I modify a Word document that contains a lot of text in fonts and colors that I don't like. It's a nuisance making the same changes day after day, but when I try to record the changes in a macro, it doesn't work: the macro simply fails to record actions dealing with text colors. I do know, however, how to modify the macro and force it to work. For example, the following code, will change all pre-selected text that is non-italic and automatic color into bold green: Selection.Find.ClearFormatting With Selection.Find .Text = "" .Font.Color = wdColorAutomatic .Font.Italic = False .Wrap = wdFindStop End With Selection.Find.Replacement.ClearFormatting With Selection.Find.Replacement .Text = "" .Font.Color = wdColorGreen .Font.Bold = wdToggle End With Selection.Find.Execute Replace:=wdReplaceAll So, what's my problem? Well, the text is in a "custom color", and I don't know how to specify custom colors in a macro. When I do these changes 'manually', the Find And Replace dialogue box says this (just before I hit the "Replace All" button): Find what: Format: Font: Bold, Font color: Custom Color(RGB(101,101,101)) Replace with: Format: Font: Not Bold, Not Italic, Font color: Auto It's that "RGB" stuff that I don't know how to specify in a macro. Can you help?
-
Answer:
Hello Rambler, The specific method for an RGB color value in Visual Basic is to use the "RGB" function. As described in part of the Visual Basic online help (search phrase RGB, select RGB function) RGB(red, green, blue) The RGB function syntax has these named arguments: Part Description red Required; Variant (Integer). Number in the range 0-255, inclusive, that represents the red component of the color. green Required; Variant (Integer). Number in the range 0-255, inclusive, that represents the green component of the color. blue Required; Variant (Integer). Number in the range 0-255, inclusive, that represents the blue component of the color. For your example, the rewrite would be something like Selection.Find.ClearFormatting With Selection.Find .Text = "" .Font.Color = RGB(101, 101, 101) .Font.Italic = False .Wrap = wdFindStop End With I am somewhat surprised that your version of MS Word did not properly record the replacement. Which version are you using? On my system I did something similar and had recorded Sub A() ' ' A Macro ' Macro recorded 8/23/06 by Maniac ' Selection.Find.ClearFormatting Selection.Find.Font.Color = 6645093 Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Replacement.ClearFormatting With Selection.Find.Replacement.Font .Bold = False .Italic = False .Underline = wdUnderlineNone .Color = wdColorAutomatic End With With Selection.Find .Text = "" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll End Sub The value of RGB(101, 101, 101) can be confirmed by the following immediate window command print rgb(101,101,101) 6645093 which matches the value used above. Please make a clarification request if any part of the answer is unclear or if you need further information about this topic. I would be glad to help further. Good luck with your work. --Maniac
rambler-ga at Google Answers Visit the source
Related Q & A:
- How to get a Coordinates of a 3D Object in Android?Best solution by Game Development
- How to get a job on a cruise ship?Best solution by Yahoo! Answers
- How to get a job at a call center in Atlanta?Best solution by Yahoo! Answers
- How to get a PR?what are the conditions to get a PR?Best solution by Yahoo! Answers
- How to delete a number from mobile text?Best solution by ChaCha
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.