Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2005

Tip: Looking for answers? Try searching our database.

Code behavior re highlighting differs in 2000/2003

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mark Tangard - 25 Jan 2005 03:02 GMT
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
Klaus Linke - 26 Jan 2005 00:24 GMT
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

> 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
[quoted text clipped - 25 lines]
> Mark Tangard
> "Life is nothing if you're not obsessed." --John Waters
Mark Tangard - 31 Jan 2005 06:09 GMT
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

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

> Hi Mark,
>
[quoted text clipped - 40 lines]
>>Mark Tangard
>>"Life is nothing if you're not obsessed." --John Waters
Klaus Linke - 31 Jan 2005 18:07 GMT
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

> Hi Klaus,
>
[quoted text clipped - 10 lines]
> Mark Tangard
> "Life is nothing if you're not obsessed." --John Waters

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.