Results 1 to 20 of 28

Thread: Macro cannot find shading colour black

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #8
    The following macro does find and delete paragraphs with Shading colour Black
    Dim par As Paragraph
    For Each par In ActiveDocument.Paragraphs
        If par.Shading.BackgroundPatternColor = -0 Then
             par.Range.DELETE
        End If
    Next par
    but it seems to go through every paragraph and in large files, the deletion process often takes a lot of time making the file unresponsive. The macro below does find paragraphs with shading instantly and then deletes them quickly, however, it doesn't work with the colour black (-0, &H0&, RGB(0,0,0) etc) capturing paragraphs without shading as well.
    Selection.Find.ClearFormatting
    With Selection.Find.ParagraphFormat
         .Shading.BackgroundPatternColor = &H0&
    End With
    With Selection.Find
        .Wrap = wdFindContinue
    End With
    Do While Selection.Find.Execute = True
        Selection.DELETE
    Loop
    The specific colour of paragraphs that need to be deleted has the colour characteristics RGB(0,0,0), HSL(170,0,0).


    Would it only be the colour issue, then the first macro wouldn't work either, yet it does - do I need to specify paragraphs as the search object as in the first macro, and how does one do that in a "With x.Find" construct? [an example with black shaded paragraphs is given in the attached file]
    Attached Files Attached Files
    Last edited by Aussiebear; 06-14-2025 at 02:02 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
  •