Hi.. I’ve been struggling with this problem for a while. I have the following simple code to search for highlighted text in a document and to report each instance to a user:
With Selection.Find .Highlight = True End With ‘search through document for highlighted format Do While Selection.Find.Execute = True ‘DO SOMETHING Loop
The problem comes when there is highlighted text in tables. If the Find.Execute finds some highlighted text in a table, it will keep finding the next highlight in the table until it reaches the last highlighted text in the table. If this is the last highlighted text in the document, the code enters an INFINITE LOOP.
If there is some other highlighted text in the document after the table, then the search continues and then ends correctly.
So the problem is only when the last highlighted text in the document is in a table. I had to add some code like:
If Selection.Information(wdWithInTable) Then ‘skip the table because it causes an endless loop! While Selection.Information(wdWithInTable) Selection.MoveDown Wend End If
But of course this skips over some of the text that i want to report.
It’s driving me mad. CAn you help?