Results 1 to 20 of 28

Thread: Macro cannot find shading colour black

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Macro cannot find shading colour black

    I have a macro which should search & delete all paragraphs with black shading that works pretty well, except that it is unable to distinguish/find text with black shading colour. Here is the part of the macro that performs the search:

    Selection.Find.ClearFormatting
        With Selection.Find.ParagraphFormat
            .Shading.BackgroundPatternColor = wdColorBlack
        End With
        With Selection.Find
             .Wrap = wdFindContinue
        End With
        Selection.Find.Execute
    If 'wdColorBlack' is substituted with yellow or red, the respective paragraphs are found by the macro, i.e. in the graphic below the two yellow and one red paragraphs are effortlessly found; if 'wdColorBlack' or '0' or '&H0' are specified, paragraphs with no shading are found by the macro along paragraphs in black shading.

    VBAe.jpg

    The following articles on "colours in Word 2007" explain that certain codes for theme or colour accent are added to the final colour code - wordarticles.com/Articles/Colours/2007BuildSet.php, wordarticles.com/Articles/Colours/2007.php - yet in the XML code of the document the text with black shading has no theme or colour accent modifiers. This is the corresponding excerpt from the .docx' XML code (the shading tag is marked up):

    HTML Code:
    <w:p w:rsidR="00FE728A" w:rsidRPr="00FE728A" w:rsidRDefault="00FE728A" w:rsidP="00FE728A"><w:pPr><w:shd w:val="clear" w:color="auto" w:fill="000000"/><w:spacing w:after="0" w:line="570" w:lineRule="atLeast"/><w:rPr><w:rFonts w:ascii="scala-sans-sc-offc-pro--" w:eastAsia="Times New Roman" w:hAnsi="scala-sans-sc-offc-pro--" w:cs="Times New Roman"/><w:b/><w:bCs/><w:sz w:val="24"/><w:szCs w:val="24"/><w:lang w:val="en" w:eastAsia="en-GB"/></w:rPr></w:pPr><w:r w:rsidRPr="00FE728A"><w:rPr><w:rFonts w:ascii="scala-sans-sc-offc-pro--" w:eastAsia="Times New Roman" w:hAnsi="scala-sans-sc-offc-pro--" w:cs="Times New Roman"/><w:b/><w:bCs/><w:sz w:val="24"/><w:szCs w:val="24"/><w:lang w:val="en" w:eastAsia="en-GB"/></w:rPr><w:t xml:space="preserve">WORDS IN BLACK SHADING</w:t></w:r></w:p>
    The XML code of the text without shading:

    HTML Code:
    <w:p w:rsidR="000140C9" w:rsidRDefault="000140C9" w:rsidP="000140C9"><w:r><w:t xml:space="preserve">TEXT WITHOUT SHADING</w:t></w:r></w:p>
    XML code of yellow shading:
    HTML Code:
    <w w:rsidR="000140C9" w:rsidRDefault="000140C9" w:rsidP="000140C9"><wPr><w:shd w:val="clear" w:color="auto" w:fill="FF0000"/></wPr><w:r><w:t xml:space="preserve">TEXT IN YELLOW SHADING</w:t></w:r></w>
    How should the search parameter .Shading.BackgroundPatternColor be specified so that it finds the text with black shading?
    Last edited by Aussiebear; 06-14-2025 at 01:59 PM.

Posting Permissions

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