Code behavior re highlighting differs in 2000/2003

M

Mark Tangard

The following code works in Word 2000, but when run in 2003 the first
part of the 'If' statement doesn't work; that is, existing highlight in
the paragraph is not removed.

If Selection.End = Selection.Start Then
Selection.Paragraphs(1).Range.HighlightColorIndex = wdNoHighlight
Else
Selection.Range.HighlightColorIndex = wdNoHighlight
End If

This rather strange and apparently wasteful variation is what works in
Word 2003:

Dim r as Range
If Selection.End = Selection.Start Then
For Each r In Selection.Paragraphs(1).Range.Characters
r.HighlightColorIndex = wdNoHighlight
Next
Selection.Paragraphs(1).Range.HighlightColorIndex = wdNoHighlight
Else
Selection.Range.HighlightColorIndex = wdNoHighlight
End If

Any idea why?

TIA


Mark Tangard
"Life is nothing if you're not obsessed." --John Waters
 
K

Klaus Linke

Hi Mark,

Seems to work fine for me (Word 2003)...

Maybe there's something special about your document, or the current paragraph?

Is the first branch entered at all?

Does this work...
If Selection.Type = wdSelectionIP Then
?

Regards,
Klaus
 
M

Mark Tangard

Hi Klaus,

Predictably, it works just fine today using either method!

Is testing Selection.Type = wdSelectionIP preferable (smarter/safer/etc) to
testing whether Selection.End and Selection.Start are the same? Besides being
more concise, I mean?

Thanks,
Mark
 
K

Klaus Linke

Let's hope it keeps working :)

I suggested Selection.Type only because I was confounded, hoping it might turn
up something weird about the selection you were working on.

Regards,
Klaus
 

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