Thread: [Solved] vba control of shading
View Single Post
 
Old 04-08-2021, 12:47 AM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

You didn't provide a document so I can't tell you what works for your document. You can record adding shading to text so you know what the code should be looking for. Then you can use that in your macro. Note that colours specified from the theme palette are NOT the same as an RGB colour specification.

This code works for me and includes two options that match my test doc depending on whether I specified the colour as RGB or via the palette
Code:
Sub FindShade()
  Dim wR As Range, wF As Find
  Set wR = ActiveDocument.Content
  Set wF = wR.Find
  With wF
    .ClearFormatting
    .Font.Shading.Texture = wdTextureNone
    '.Font.Shading.BackgroundPatternColor = -738132122   'this is a theme colour tint
    .Font.Shading.BackgroundPatternColor = 15652541     'this is a RGB colour that matches the theme colour
    .Text = ""
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = True
    Do While .Execute = True
      wR.Select
      wR.Font.Bold = True
    Loop
  End With
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote