Results 1 to 4 of 4

Thread: Find shading?

  1. #1
    New Lounger
    Join Date
    Sep 2016
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Find shading?

    Hi folks,

    One of my clients just gave me a document in which they marked a bunch of text using a very pale blue shading. I'd like to do a Find-and-Replace to remove the shading but I don't see shading as an option in the Find dialog. How would I do this?

    Thanks in advance,

    Beej

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    Beej

    Is there other shading that needs to be retained? If not, you could simply select all and set everything to a clear background. You can search for highlighted text but the find/replace dialog doesn't look like it allows searching for a background shading. Perhaps it is possible in VBA but you would need to know where the shading is applied in advance (refer following para)

    Note that shading can be tricky to remove sometimes. It could be applied at the table cell, paragraph or text level and therefore needs to be removed from the correct level.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. The Following User Says Thank You to Andrew Lockton For This Useful Post:

    Beej@impact (2016-10-03)

  4. #3
    New Lounger
    Join Date
    Sep 2016
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thanks as always Andrew.

    In this case I wanted to replace the shading with blue text so a straight up "No shading" wouldn't do the trick.

    I'll give Microsoft the benefit of the doubt and assume the fact that shading can be applied at different levels is exactly why they didn't allow for it in the Find dialog.

  5. #4
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    And to make matters worse, a shading is a mix of foreground colour, background colour and a texture so it is exceptionally hard to work out how to find a particular background colour.

    This klunky macro attempts to solve your problem and applies a character style to get the blue text. You would have to tweak it to actually work in your document since I don't know what shading you are actually searching for.
    Code:
    Sub ReplaceShadingWithCharStyle()
      Dim aPar As Paragraph, aChar As Range
      For Each aPar In ActiveDocument.Paragraphs
        If aPar.Range.Font.Shading.Texture <> wdTextureNone Then
          Debug.Print aPar.Range.Text, aPar.Range.Characters.Count
          For Each aChar In aPar.Range.Characters
            If aChar.Shading.BackgroundPatternColor = -738131969 Then
              aChar.Style = "Emphasis"
             aChar.Shading.BackgroundPatternColor = -16777216
            End If
          Next aChar
        End If
      Next aPar
    End Sub
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  6. The Following User Says Thank You to Andrew Lockton For This Useful Post:

    Beej@impact (2016-10-04)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •