Pages: 1
Print
Author Topic: How to determine the end of the document?  (Read 1081 times)
biswajitsr
Member

Posts: 44


« on: May 03, 2010, 11:57:03 PM »

I am using range object to traverse the document and paste a certain string withing the document. I am using the movedown method fo that purpose.
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 1550



WWW
« Reply #1 on: May 04, 2010, 12:07:53 PM »

I think we need a more information.

One way to get to the end the document using only Range is as follows. The Select() is added so you can see where you end up.

Code:
rng = ActiveDocument.Range;
rng.MoveToDocumentStart();
rng.SelectContainerContents();
rng.Collapse(sqCollapseEnd);
rng.Select();

This gets you there as well:

Code:
docNode = ActiveDocument.documentElement;
rng = ActiveDocument.Range;
rng.SelectAfterNode(docNode);
rng.Select();

Or this:

Code:
rng = ActiveDocument.Range;
rng.MoveToDocumentEnd();
rng.Select();

There are probably many other ways. Are these even close to what you are doing?
« Last Edit: May 31, 2010, 04:24:57 PM by Derek Read » Logged
biswajitsr
Member

Posts: 44


« Reply #2 on: May 04, 2010, 11:35:53 PM »

I am using range object to traverse the document and paste a certain string withing the document. I am using the movedown method for that purpose. But I am thinking when traversing if end of the document reached then null exception may occur. So is there any way to know when reached to end of the document?
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 1550



WWW
« Reply #3 on: May 05, 2010, 12:49:37 PM »

How about checking inside your loop to see if the current node, Range.ContainerNode is equal to ActiveDocument.documentElement.

When that check returns true then jump out of the loop (if your scripting language provides that mechanism) or use the equivalent of "while not" in your scripting language for the type of loop.
« Last Edit: May 05, 2010, 02:36:20 PM by Derek Read » Logged
Pages: 1
Print
Jump to: