1 Attachment(s)
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:
Code:
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.
Attachment 21953
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?
Specify HSL value in macro
Can one search for the colour's HSL value? The macros below search for the Hex and RGB color values respectively:
Code:
With Selection.Find.ParagraphFormat
.Shading.BackgroundPatternColor = &HFFFF&
.Shading.BackgroundPatternColor = RGB (255,255,0)
Can HSL value be likewise specified? It can come in very handy when searching for a specific black colour HSL(x,0,0) where x can be any number 0-255, while RGB cannot differentiate here at all ... Thank you