You actually don't need to worry about "reaching the end of the document." Thankfully, the tables are stored in a Tables
collection which is a property of a Word.Document
. You can iterate through all the tables like so:
For Each oTable In objNewDoc.Tables
If Left(oTable.Cell(1, 1).Range.Text, Len(oTable.Cell(1, 1).Range.Text) - 2) = "Some string" Then
MsgBox "Found one!"
End If
Next
One issue I ran into when putting this together is that all Cells' Text have an End-of-Cell Marker composed of two characters: a Carriage Return (ascii 13) followed by a BELL (ascii 7). I used Left
to strip those off so I could compare the text against a string value, which is what I understand you are trying to do.