find highlighting, replace with shading

A

adgorn

1)I have document with multiple words highlighted in bright green. My users
can't read printed versions. One sent me an exmple of a shading that she
would like me to replace the bright green with. How do I replace all
instances of bright green highlighting with this particular shading? (btw How
do you deterrmine some kind of code for this shade she sent me??)

2) Word find/replace can search for highlighting. Can it also search for
shading?

Thanks.
 
J

Jay Freedman

First define a character style that uses the default paragraph font
settings and adds only the shading. To do this:

- Open the New Style dialog (from Format > Style in older versions of
Word, or from the Styles and Formatting task pane in newer versions).
- Set the style type to Character, enter a name, and check the Add to
Template box.
- Click the Format button and select Border to open the Borders &
Shading dialog. Click the Shading tab.
- Select the color you want; if necessary, click the More Colors
button and use the color picker.
- Click OK in each dialog.

Now you can use Find&Replace to find highlighting and replace with the
character style. Click the More button in the Replace dialog. With the
cursor in the Find What box, click Format > Highlight. With the cursor
in the Replace With box, click Format > Highlight twice (so the label
under the box says "Not Highlight") and Format > Style > choose your
character style. Click the Replace All button.

You could write a macro to do it, but it would be overkill if only one
document is involved. Note that, because of a bug, you _cannot_ use
the macro recorder to record the actions in the Replace dialog -- it
simply won't record anything involving formatting. :-b See
http://www.word.mvps.org/FAQs/MacrosVBA/ModifyRecordedMacro.htm.

A macro would be necessary if the original document contains more than
one color of highlighting and you want to replace only the bright
green. If that's the case, post back for more help.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
A

adgorn

This choice on the Format button is not available and is grayed out:
....select Border to open the Borders & Shading dialog.

Also I do have to do this for 25 docs so maybe a macro would be better.

Thanks.
 
J

Jay Freedman

This choice on the Format button is not available and is grayed out:
...select Border to open the Borders & Shading dialog.

Also I do have to do this for 25 docs so maybe a macro would be better.

Thanks.

I don't understand how the Borders choice would not be available in
the New Style > Format menu, but the macro makes that a moot point.

Use the following macro, with the instructions at
http://www.gmayor.com/installing_macro.htm. Be sure to edit the lines
that create the style name and color, indicated by the comment.

Sub HighlightToShade()
Dim myRg As Range
Dim StyleExists As Boolean
Dim TestStyle As Style
Dim StyleName As String
Dim StyleColor As Long

' CHANGE THESE VALUES TO SUIT YOUR NEEDS:
StyleName = "ShadeLtGreen"
StyleColor = RGB(227, 255, 171)

With ActiveDocument
' find out whether this style already exists
For Each TestStyle In .Styles
If LCase(TestStyle.NameLocal) = LCase(StyleName) Then
StyleExists = True
Exit For
End If
Next

If Not StyleExists Then
.Styles.Add Name:=StyleName, Type:=wdStyleTypeCharacter
.Styles(StyleName).Font.Shading.BackgroundPatternColor = _
StyleColor
End If

Set myRg = .Range
With myRg.Find
.ClearFormatting
.Highlight = True
.Replacement.ClearFormatting
.Replacement.Style = ActiveDocument.Styles(StyleName)
.Replacement.Highlight = False
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.Execute Replace:=wdReplaceAll
End With
End With
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
A

adgorn

Works great! I even figured out how to find other rgb values from the color
palette on my own, so I can play around a bit.

The macro also changes the font to Arial 9pt and seems to reverse whatever
bolding was there. Actually that may be beneficial. But what controls the
font choice? I may not want this change or I may want to go to another font.

Thanks for taking your time to help me.
 
A

adgorn

Works great! I even figured out how to change the rgb from the color palette
so I can play around a bit.

One issue: The macro also changed the font to arial 9pt and reversed the
bolding in effect. Actually that may be OK, but what controls the font
choice? I may need to go back to what it was originally or choose some other
font.

Thanks for taking your time to help me.
 
J

Jay Freedman

A character style that doesn't specify any other font is defined to
use "Default Paragraph Font", as this one does. A side effect of
applying the character style is that it removes any directly applied
formatting and returns you to the format defined in the current
paragraph style. Sorry, but there's no way to avoid that (other than a
character-by-character search for direct formatting, which would be
very slow).

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
A

adgorn

Since all the shaded words are now of the style you created called
"shadelightgreen", I can go to that style now and just change the font size
and bold setting to whatever I want and it will update all of them, so that
works fine.

I think this will work very well. Again, thank you!
 
J

Jay Freedman

I was under the mistaken impression that only some parts of the
highlighted text were in a different font or weight. When that's the
case, you need to keep the style's font as "Default Paragraph Font".

But if all of the highlighted text to be shaded should be the same
font and weight, you can include those in the definition of the style
when the macro sets it up. For example:

If Not StyleExists Then
.Styles.Add Name:=StyleName, Type:=wdStyleTypeCharacter
.Styles(StyleName).Font.Name = "Times New Roman"
.Styles(StyleName).Font.Size = 10
.Styles(StyleName).Font.Bold = True
.Styles(StyleName).Font.Shading.BackgroundPatternColor = _
StyleColor
End If

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top