Andreas Hermle
asked on
Retrieve the index number of specific tables and display them in a msgbox
Dear Experts:
Below macro searches for the string 'Single Products' in the active Document. If this string is located in a table, the macro will come up with a msgbox telling the user that the string has been found.
Could somebody please tweak this macro so that all the index numbers of the tables where the string has been found are listed in a msgbox, e.g.
"The string 'Single Products' has been found in tables (1), (3), (5)."
Help is much appreciated. Thank you very much in advance for your valuable help.
Regards, Andreas
Below macro searches for the string 'Single Products' in the active Document. If this string is located in a table, the macro will come up with a msgbox telling the user that the string has been found.
Could somebody please tweak this macro so that all the index numbers of the tables where the string has been found are listed in a msgbox, e.g.
"The string 'Single Products' has been found in tables (1), (3), (5)."
Help is much appreciated. Thank you very much in advance for your valuable help.
Regards, Andreas
Sub Search_Table()
Dim ht As Single
Dim strLen As Integer
Dim rng As Range
Dim strFind As String
'The index number of the tables that have the string 'Single Products' have to be listed in a MsgBox at the End
strFind = "Single Products"
strLen = Len(strFind)
Set rng = ActiveDocument.Range
With rng
.Find.ClearFormatting
With .Find
.Text = strFind
.Execute
End With
Do
If .Find.Found Then
If rng.Information(wdWithInTable) Then
MsgBox "String has been found"
End If
End If
If Not .Find.Found Then
MsgBox "String has not been found"
End If
rng.MoveStart strLen
.Find.Execute
Loop Until Not (.Find.Found)
End With
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks Rafael. I can't think why that didn't come out in my testing.
ASKER
Wow, I am impressed. How come that you both know all this? Of course it is partly experience and lots of coding jobs but there is also this gene that all you programmers have and the rest of us not.
Thank you very much for your great help. Regards, Andreas
Thank you very much for your great help. Regards, Andreas