Thread: [Solved] vba control of shading
View Single Post
 
Old 04-07-2021, 10:27 PM
Tony Tony is offline Windows 10 Office 2019
Novice
 
Join Date: Apr 2021
Posts: 12
Tony is on a distinguished road
Default vba control of shading

I want to determine the range for all shaded (not highlighted) text in my document. The problem is that I don't know the colors of all the shades used. I've written some code to find those colors and their ranges, but it's messy and doesn't work well (see below). I have hundreds of documents I want to do this with.

I've read that typing CTRL-a, CTRL-q, CTRL-spacebar will remove all direct formatting, and when I do this all shades in the document disappear. I conclude they must all be direct formatting. This suggests they are not "styles" vba objects, and yet the Style listing of the user interface has entries for every shading (and other formatting).

The screenshot shows part of the document with the Styles and Style Inspector. I put my cursor on the word 'big' and then used the 'select all 154 instances" -- here the selected words show as gray, but the Style Inspector shows "Pattern: Solid (100%) (White)". But if I put my cursor in the pink text 'bar', I see "Pattern: Solid (100%) (Custom Color(RGB(255,191,255)))" I'm not interested in the White shaded text, but I am interested in all other colors. This Style list interface provides great control, but I need to use vba since I have many large, complex documents like this.

I've literally spent days on this and would appreciate any help.

here's some of the code I mentioned above:
Code:
Set wR = wDoc.Content
wR.Find.ClearFormatting
wR.Find.Font.Shading.BackgroundPatternColor = wdColorAutomatic
Set wF = wR.Find
With wF
  .Text = ""
  .Replacement.Text = ""
  .Forward = True
  .Wrap = wdFindStop
  .Format = True
End With
Do While wF.Execute = True
...[lots of code]...
Loop

Last edited by Tony; 04-07-2021 at 11:28 PM. Reason: added link to screenshot
Reply With Quote