Consulting

Results 1 to 20 of 28

Thread: Mail Merge - Conditional formatting of cell background color

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #16
    VBAX Regular
    Joined
    Mar 2019
    Posts
    7
    Location
    Quote Originally Posted by macropod View Post
    Yes, and the instructions in post 6 show how to do that.
    If I am understanding correctly, those instructions don't change the background color for the entire cell, just the text background of the specified field, so that if there are other merge fields or text in the cell, it will only highlight the specified field and not the whole table cell.

    I was able to conditionally shade the entire cell by running this VBA macro after the mail merge.

    Sub color()
    Dim r As Range, text As String, backgroundColor As WdColorIndex
        Set r = ActiveDocument.Range
        text = "TOXIN"
        backgroundColor = wdGray25
        With r.Find
           Do While .Execute(FindText:=text, MatchWholeWord:=True, Forward:=True) = True
        r.Cells(1).Shading.BackgroundPatternColorIndex = backgroundColor
           Loop
        End With
    End Sub
    Last edited by Aussiebear; 04-02-2023 at 12:54 PM. Reason: Added code tags to supplied code

Posting Permissions

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