T
Tony Jollans
I have now had a chance to look at the real document (thanks, Greg) and the
problem is caused by formatting being applied to table cells - complete
cells rather than just the (textual) content.
I can't say for sure what happens but end-of-cell markers have an uneasy
relationship with F&R - you cannot search for them, nor will they be
included in the Found Range even if they satisfy the Find criteria.
When a (complete) table cell is formatted (highlighted in this case, but
other formatting seems to have the same effect) and that formatting is
Found, the Found Range is set to the text in the cell, not the complete
cell. When Find then looks forward to find the next instance it doesn't seem
unreasonable to assume that it might find the end-of-cell marker and, on
setting the found Range to it, automatically select the whole cell (which is
what happens when you select the end-of-cell normally) but Find seems to
override the cell selection and limit the selection to the (non-existent)
space between the last character and the end-of-cell marker. And so it
loops, except that ...
... it only seems to happen in VBA (not via the UI), and ...
... it only seems to happen when there are no more instances in the
document to find.
There doesn't seem to be any easy way to distinguish formatting applied to
cell contents from formatting applied to the cell - although I could have
missed something.
Greg's solution of checking for a zero length happened to work but there are
other situations where that can occur so it is not a general purpose
workaround. All I can think of immediately is checking the range and
comparing it to the previous found range. Maybe someone else has an idea.
I hope all that made some kind of sense.
problem is caused by formatting being applied to table cells - complete
cells rather than just the (textual) content.
I can't say for sure what happens but end-of-cell markers have an uneasy
relationship with F&R - you cannot search for them, nor will they be
included in the Found Range even if they satisfy the Find criteria.
When a (complete) table cell is formatted (highlighted in this case, but
other formatting seems to have the same effect) and that formatting is
Found, the Found Range is set to the text in the cell, not the complete
cell. When Find then looks forward to find the next instance it doesn't seem
unreasonable to assume that it might find the end-of-cell marker and, on
setting the found Range to it, automatically select the whole cell (which is
what happens when you select the end-of-cell normally) but Find seems to
override the cell selection and limit the selection to the (non-existent)
space between the last character and the end-of-cell marker. And so it
loops, except that ...
... it only seems to happen in VBA (not via the UI), and ...
... it only seems to happen when there are no more instances in the
document to find.
There doesn't seem to be any easy way to distinguish formatting applied to
cell contents from formatting applied to the cell - although I could have
missed something.
Greg's solution of checking for a zero length happened to work but there are
other situations where that can occur so it is not a general purpose
workaround. All I can think of immediately is checking the range and
comparing it to the previous found range. Maybe someone else has an idea.
I hope all that made some kind of sense.