Hi,
have a look at this one:
Sub Test4a()
Dim oRow As Row
Dim rTmp As Range
Dim sTmp As String
If Selection.Information(wdWithInTable) = False Then Exit Sub
Set rTmp = Selection.Range
' TargetText = Chr(88) Or Chr(120) ' type mismatch
For Each oRow In Selection.Tables(1).Rows
sTmp = Left(oRow.Cells(2).Range.Text, 1)
If sTmp = Chr(88) Or sTmp = Chr(120) Then ' watch out
rTmp.Start = oRow.Cells(5).Range.Start
rTmp.End = oRow.Cells(8).Range.End
rTmp.Shading.Texture = wdTextureNone
rTmp.Shading.ForegroundPatternColor = wdColorAutomatic
rTmp.Shading.BackgroundPatternColor = wdColorGray15
End If
Next oRow
End Sub
Note that this one doesn't work:
TargetText = Chr(88) Or Chr(120) ' type mismatch
Chr(88) Or Chr(120) returns a boolean
which can not be assigned to a string.
--
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Vista Small Business, Office XP