Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2006

Tip: Looking for answers? Try searching our database.

find highlighting, replace with shading

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
adgorn - 07 Oct 2006 16:47 GMT
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.
Signature

Alan

Jay Freedman - 07 Oct 2006 18:30 GMT
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        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

>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
[quoted text clipped - 6 lines]
>
>Thanks.
adgorn - 08 Oct 2006 11:32 GMT
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.

Signature

Alan

> First define a character style that uses the default paragraph font
> settings and adds only the shading. To do this:
[quoted text clipped - 43 lines]
> >
> >Thanks.
Jay Freedman - 08 Oct 2006 19:09 GMT
>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        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
adgorn - 08 Oct 2006 20:19 GMT
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.

Signature

Alan

> >This choice on the Format button is not available and is grayed out:
> >...select Border to open the Borders & Shading dialog.
[quoted text clipped - 59 lines]
> Email cannot be acknowledged; please post all follow-ups to the
> newsgroup so all may benefit.
adgorn - 08 Oct 2006 20:21 GMT
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.
Signature

Alan

> >This choice on the Format button is not available and is grayed out:
> >...select Border to open the Borders & Shading dialog.
[quoted text clipped - 59 lines]
> Email cannot be acknowledged; please post all follow-ups to the
> newsgroup so all may benefit.
Jay Freedman - 08 Oct 2006 21:16 GMT
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        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

>Works great!  I even figured out how to change the rgb from the color palette
>so I can play around a bit.
[quoted text clipped - 69 lines]
>> Email cannot be acknowledged; please post all follow-ups to the
>> newsgroup so all may benefit.
adgorn - 09 Oct 2006 01:31 GMT
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!
Signature

Alan

> 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
[quoted text clipped - 84 lines]
> >> Email cannot be acknowledged; please post all follow-ups to the
> >> newsgroup so all may benefit.
Jay Freedman - 09 Oct 2006 03:32 GMT
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        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

>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
[quoted text clipped - 91 lines]
>> >> Email cannot be acknowledged; please post all follow-ups to the
>> >> newsgroup so all may benefit.

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.