DotNetGuy
08-28-2005, 09:39 AM
Good day;
I need to search the contents of the first cell of each row of all tables in my document for a specific string. I've found some good code here, like determining if a table cell is empty, however, I'm getting an exception when I run in to a table where there are vertically merged cells. Can anyone give me some guidance on how to handle the exception or better yet successfully search the vertically merged cells?
Many thanks.
p.s. - Several of the tables have nested tables but none of the child tables will ever have the text I'm looking for.
Dim tempTable As table
Dim tempRow As row
Dim tempCell As cell
Dim tempText As String
Dim i As Integer
Dim rowCount As Integer
Dim tableCount As Long
Dim cel As cell
' CountReqRows Macro
' Macro created 28 August 2005
'
' This macro will inspect ALL the tables in the document
' looking for the text "SA" in the first cell of each row
For Each tempTable In ActiveDocument.Tables
For Each tempRow In tempTable.Rows
For i = 1 To 1
If InStr(tempRow.Cells(1).Range.Text, "SA") > 0 Then
rowCount = rowCount + 1
End If
Next i
Next tempRow
Next tempTable
MsgBox ("Total target rows found are: " & rowCount )
rowCount = 0
End Sub
I need to search the contents of the first cell of each row of all tables in my document for a specific string. I've found some good code here, like determining if a table cell is empty, however, I'm getting an exception when I run in to a table where there are vertically merged cells. Can anyone give me some guidance on how to handle the exception or better yet successfully search the vertically merged cells?
Many thanks.
p.s. - Several of the tables have nested tables but none of the child tables will ever have the text I'm looking for.
Dim tempTable As table
Dim tempRow As row
Dim tempCell As cell
Dim tempText As String
Dim i As Integer
Dim rowCount As Integer
Dim tableCount As Long
Dim cel As cell
' CountReqRows Macro
' Macro created 28 August 2005
'
' This macro will inspect ALL the tables in the document
' looking for the text "SA" in the first cell of each row
For Each tempTable In ActiveDocument.Tables
For Each tempRow In tempTable.Rows
For i = 1 To 1
If InStr(tempRow.Cells(1).Range.Text, "SA") > 0 Then
rowCount = rowCount + 1
End If
Next i
Next tempRow
Next tempTable
MsgBox ("Total target rows found are: " & rowCount )
rowCount = 0
End Sub