• color cells based in cell string

    From Daniel Spitale@21:1/5 to All on Sat Jan 23 10:08:16 2021
    Hello forum,
    I have many tables in word documents and I want to color (background color) the cells according to specific string. Below my code but nothing happen when I run it.

    Sub colora()
    Dim MyTable As Table
    Dim MyRow As Row
    Dim MyCell As Cell
    For Each MyTable In ActiveDocument.Tables
    For Each MyRow In MyTable.Rows
    For Each MyCell In MyRow.Cells
    If MyCell.Range.Text = "ottimo" Then
    MyCell.Shading.BackgroundPatternColor = wdColorBlue
    ElseIf MyCell.Range.Text = "ottimo-buono" Then
    MyCell.Shading.BackgroundPatternColor = wdColorGreen
    End If
    Next MyCell
    Next MyRow
    Next MyTable
    Set MyCell = Nothing
    Set MyRow = Nothing
    Set MyTable = Nothing
    End Sub

    However, if I use the code below it works, but not exactly as I want because both the conditions are colored in blue.
    Where I'm wrong??
    Thank you for any help!
    Daniel

    Sub colora()
    Dim MyTable As Table
    Dim MyRow As Row
    Dim MyCell As Cell
    For Each MyTable In ActiveDocument.Tables
    For Each MyRow In MyTable.Rows
    For Each MyCell In MyRow.Cells
    If MyCell.Range.Text Like "ottimo*" Then
    MyCell.Shading.BackgroundPatternColor = wdColorBlue
    ElseIf MyCell.Range.Text Like "ottimo-buono" Then
    MyCell.Shading.BackgroundPatternColor = wdColorGreen
    End If
    Next MyCell
    Next MyRow
    Next MyTable
    Set MyCell = Nothing
    Set MyRow = Nothing
    Set MyTable = Nothing
    End Sub

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)