I'm having trouble creating a Microsoft-Word macro. Here's the macro that I'm working on. It successfully selects each individual table in a word document.
Sub FindSpecificTables()
Selection.WholeStory
Dim iResponse As Integer
Dim tTable As Table
'If any tables exist, loop through each table in collection.
For Each tTable In ActiveDocument.Tables
tTable.Select
If response = vbNo Then Exit For 'User chose to leave search.
Next
MsgBox prompt:="Search Complete.", buttons:=vbInformation
End Sub
However, I only need to select a table if the table contains a specified string. This should be simple enough, but I can't figure it out. How can I search a table for a specific string?
I've tried adjusting the code with the following conditional statement:If tTable.Cell(1, 1) = "Adjusted:" Then tTable.Select
; see example below.
Sub FindSpecificTables()
Selection.WholeStory
Dim iResponse As Integer
Dim tTable As Table
'If any tables exist, loop through each table in collection.
For Each tTable In ActiveDocument.Tables
If tTable.Cell(1, 1) = "MySpecifiedString:" Then tTable.Select
If response = vbNo Then Exit For 'User chose to leave search.
Next
MsgBox prompt:="Search Complete.", buttons:=vbInformation
End Sub
Unfortunately, this isn't working. Is my syntax wrong? Do you guys have any suggestions or recommendations?