Consulting

Page 2 of 2 FirstFirst 1 2
Results 21 to 28 of 28

Thread: Mail Merge - Conditional formatting of cell background color

  1. #21
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,442
    Location
    The answer is simple: repeat all of the static text inside each field.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  2. #22
    VBAX Regular
    Joined
    Mar 2019
    Posts
    7
    Location
    Quote Originally Posted by macropod View Post
    The answer is simple: repeat all of the static text inside each field.
    The additional text isn't static, it's other mail merge fields.

  3. #23
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,442
    Location
    Quote Originally Posted by AbbyPi View Post
    The additional text isn't static, it's other mail merge fields.
    So replicate those mergefields, too. This isn't rocket science... And, as I said in post 12:
    All your attachment is is an image. There is no way anyone can assess what you've done from that
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  4. #24
    VBAX Newbie
    Joined
    Sep 2020
    Posts
    1
    Location

    Mail Merge Conditional Formatting Cell Background Coloud

    Hi All,

    I followed the instructions above and use this as a reference:

    {IF{MERGEFIELD Condition}= "HIGH" "→→↵
    →→↵
    →→" \* Charformat}{IF{MERGEFIELD Condition}= "MID" "→→↵
    →→↵
    →→" \* Charformat}{IF{MERGEFIELD Condition}= "LOW" "→→↵
    →→↵
    →→" \* Charformat}

    I've set the margins (all sides) to 0, the tab is set to cell width, it's right-aligned, I use TAB (ctrl-TAB) because it's inside the cell, and for RETURN (shift-enter).but all I got is "Unknown Switch Argument". Please help

    Here's a screenshot of current work. I highlighted them to show the tabs.

    mailmerge cell colour.jpg
    Attached Images Attached Images

  5. #25
    VBAX Newbie
    Joined
    Aug 2022
    Posts
    2
    Location

    Multiple actions

    "This worked like a dream! I am very rusty with VBA though, can someone please tell me how to ask it to perform multiple actions. I forget which part of the code I need to copy for it to repeat.

    I would like it to find the following and shade the cell that colour:

    text = "W4"
    backgroundColor = wdRed


    text = "W5"
    backgroundColor = wdRed


    text = "W6"
    backgroundColor = wdYellow


    text = "W7"
    backgroundColor = wdYellow


    text = "W8"
    backgroundColor = wdGreen


    text = "W9"
    backgroundColor = wdGreen


    Thanks


    Quote Originally Posted by AbbyPi View Post
    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

  6. #26
    VBAX Contributor
    Joined
    Jul 2020
    Location
    Sun Prairie
    Posts
    126
    Location
    Quote Originally Posted by AbbyPi View Post
    I agree that this works and I had no problem getting it to work with only one field in the cell.

    However, because it uses text highlighting and not cell background shading, it does not work with additional text outside the field code, which was pointed out and which is what I was hoping to solve by asking for help in this forum. I apologize if my question was not clear.
    Can you put your additional text inside the field code?

  7. #27
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,442
    Location
    Quote Originally Posted by Nikko77 View Post
    "This worked like a dream! I am very rusty with VBA though, can someone please tell me how to ask it to perform multiple actions. I forget which part of the code I need to copy for it to repeat.

    I would like it to find the following and shade the cell that colour:
    The solution discussed extensively in this thread requires no VBA.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  8. #28
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,442
    Location
    Quote Originally Posted by Chas Kenyon View Post
    Quote Originally Posted by AbbyPi View Post
    I agree that this works and I had no problem getting it to work with only one field in the cell.

    However, because it uses text highlighting and not cell background shading, it does not work with additional text outside the field code, which was pointed out and which is what I was hoping to solve by asking for help in this forum. I apologize if my question was not clear.
    Can you put your additional text inside the field code?
    Charles: All you're doing here is replying to a question that was answered years ago... See posts #21 & #23.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

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