End of document marker?

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.
 
K

Karen

Hi Tony,

Thanks so much. There is no way I would have found the fundamental problem.
So, I'm now inserting my own highlighted end of document marker and it's
working fine on several different yet related docs. It's really nice to now
know the root of the problem and why it varied from document to document.
Now, if I could troubleshoot like that...............:)

--
Karen
"Tony Jollans" <My Forename at My Surname dot com> wrote in message
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.
 
G

Greg

Tony,

Yes it makes some kind of sense. Trouble is, I can't seem to be able
to apply "highlighting" to a complete cell in a simple document so I
can step through it and view your observations.
 
T

Tony Jollans

So what happens when you select a (complete - non-empty) cell and click on
the highlight button?
 
G

Greg

Only the text in the cell is highlighted and the macro runs as expected
with no continous loop.
 
T

Tony Jollans

Just to be sure I tried again.

New Document
New Table (default 2 rows 5 columns but it makes no difference for me)
Random text in a single cell (the first but any one does it for me)
Select the cell
Click on Highlight - the text shows highlighted.
Run this:

Sub Macro6()
'
' Macro6 Macro
' Macro recorded 27/01/2006 by Tony
'
Selection.Find.ClearFormatting
Selection.Find.Highlight = True
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
While Selection.Find.Execute
Wend
End Sub

It loops.
Break out of the loop
Undo the highlight
Select the text but NOT the cell
Click on Highlight
Run the code again
It finishes cleanly

I am running Word 2003 (on Win XP Pro SP1) but without updates.

Interestingly, I just quickly tried it on another machine (Word 2000 on Win
Me) and it didn't loop so some more investigation is called for :)
 
G

Greg

Tony,

Ran your test here. No loop (Word 2000). Will try tonight at home
(Word2003) and suspect that I will see the loop.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top