ActiveDocument.Content vs ActiveDocument.Range

G

Gordon Bentley-Mix

Can anyone tell me the difference between ActiveDocument.Content and
ActiveDocument.Range? From reading the VBA help it appears that if you don't
specify a Start or End for ActiveDocument.Range it works the same as
ActiveDocument.Content.

Or have I missed something...?
--
Cheers!
Gordon
The Kiwi Koder

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 
S

StevenM

To: Gordon,

Not that books are necessarily an infallable source of knowledge, but the
text "Writing Word Macros" by Steven Roman (1999), states:

"The Document object has a property called Content and a method called
'Range' that return a Range object representing the entire main document
story. Thus, the line:

Set rng = ActiveDocument.Content
Set rgn = ActiveDocument.Range

each create a Range object that refers to the main document story" (p. 222).

What I do to figure out what my code is doing is to add a line with

oRange.Select

(or to use the same nominclature)

rgn.Select

and then try to see if I can see what is happening in the active document.
But then I assume you've already tried that.

For what its worth, it seems to me that VBA as a fair amount of redundancy
built into it, especially when it comes to Range objects.

Steven Craig Miller
 
C

Cindy M.

Hi Gordon,
Can anyone tell me the difference between ActiveDocument.Content and
ActiveDocument.Range? From reading the VBA help it appears that if you don't
specify a Start or End for ActiveDocument.Range it works the same as
ActiveDocument.Content.

Or have I missed something...?
Content is a property of the Document object that returns a Range that equals
the entire MainDocument story (no headers, footers, etc.) This property is
available only for the Document object. It's like using myTable.Range or
myBookmark.Range.

Document.Range is actually a method that returns a Range object. IMO it was a
mistake to create an object, a property and a method with the same name.
Probably this is how we ended up with Content for the document range - at a
later point someone realized the Developer is going to need that Range object
on a regular basis and would have no straight-forward way to access it. If that
had been clear earlier, the method would probably be named something like
GetRange.

In VBA the result of the Document.Range is the same as Document.Content because
the default of the optional parameters returns the start and end points of the
MainDocument story. In other programming languages (such as C#) these
parameters are not optional and there is no default value provided, so the
result and usage of Content and Range are not the same. For this reason, I
always try to use Content when I mean "the entire main document story".

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

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

Gordon Bentley-Mix

Thanks for the comprehensive answer, Cindy. I now have a much better
understanding of the concepts.
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 

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

Similar Threads


Top