set range to end of document

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

set range to end of document

Post by Robie »

Hi

How could I set a range to end of document easily, i.e. so that I can set the properties of the last paragraph or insert a new paragraph at the end of the range (document)? I keep doing this but it *doesn't* quite seem right to me!

Code: Select all

    Set newRange = docNew.Content
    newRange.Collapse Direction:=wdCollapseEnd
Thanks.

Robie

User avatar
HansV
Administrator
Posts: 78445
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: set range to end of document

Post by HansV »

If you want to insert a new paragraph at the end of the document:

ActiveDocument.Content.InsertParagraphAfter

To insert some text at the end of the document:

ActiveDocument.Content.InsertAfter "Blah blah blah"

To refer to the last paragraph in the document, you can use

ActiveDocument.Paragraphs(ActiveDocument.Paragraphs.Count)

You can also refer to the end of the document through the predefined \EndOfDoc bookmark:

ActiveDocument.Bookmarks("\EndOfDoc").Range
Best wishes,
Hans

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

Re: set range to end of document

Post by Robie »

Thanks Hans.