WORD Automation - Document.Characters.Count Property

P

Philip

I am using the WORD object model and opening a WORD
document for the purpose of replacing various words. I
am selecting a RANGE using a start location of "0" and
then using the Document.Characters.Count property as the
end location (as suggested from MSDN). When I set the
RANGE and SELECT...... only about 90% of the document is
selected.

Any idea why this technique is not selecting the entire
document ?

Is there another technique that can be used with a RANGE
to select the entire document ?

Thanks

Philip
 
C

Cindy Meister -WordMVP-

Hi Philip,

Well...

1) You should avoid SELECTION and SELECT unless you
absolutely need them

2) Find / Replace can certainly be done with the RANGE
object. And if you don't select anything at all, just start
at the top of the document, .Find with the Selection object
will run through all the text (in the main story).

3) If you really want to select the entire document, then
ActiveDocument.Range.Select

4) If the document contains hidden text, or fields, it
could explain the difference you're seeing.
TextRetrievalMode needs to be set to not pick up hidden
text and fields to get a similar match with .Count and
setting a range.

5) And finally, the code for Word in the various KB
articles is mostly a bunch of said:
I am using the WORD object model and opening a WORD
document for the purpose of replacing various words. I
am selecting a RANGE using a start location of "0" and
then using the Document.Characters.Count property as the
end location (as suggested from MSDN). When I set the
RANGE and SELECT...... only about 90% of the document is
selected.

Any idea why this technique is not selecting the entire
document ?

Is there another technique that can be used with a RANGE
to select the entire document ?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Jan 24 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 

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