|
|
|
 |
Determine whether the insertion point is located at the end of a document
|
Article contributed by Bill Coan

If you're already familiar with Start and End properties of
objects in a Word document, feel free to skip to the end of this article for
two helpful code snippets. Otherwise, read on to learn about Start and End
properties of objects in a Word document.
Start Property
The Start property of every item in a Word document, whether a text
character, an inline graphic, the anchor for a floating graphic, a table, or
anything else, describes how many items are situated to the left of that item.
For example, a text character at the start of a document is said to have a
Start property of 0 (zero) because zero items are situated to the left of it.
The second character in a document is said to have a Start property of 1 (one)
because there is one item situated to the left of it.
End Property
The End property of every item in a Word document describes how many items
are situated to the left of that item, including the item itself.
For example, a text character at the start of a document is said to have an
End property of 1 (one) because one item is situated to the left of it,
counting the character itself. The second character in a document is said to
have an End property of 2 (two) because there are two characters situated to
the left of it, counting itself.
A new, blank Word document contains a single empty paragraph, which is to
say, a single character that happens to be a paragraph mark. Initially, the
paragraph mark character has a Start property of 0, because zero items are
situated to the left of it, and an End property of 1, because one item is
situated to the left of it, counting itself.
When an item in a Word document is selected, Word's Selection object takes
on the Start and End properties of that Item. If multiple items are selected,
the Selection object takes on the Start property of the first item and the End
property of the last item. For example, if the entire contents of a Word
document are selected, the Selection object takes on the Start property of the
first character in the document and the End property of the final paragraph
mark.
Are We There Yet?
The following code takes advantage of this to determine whether the
selection includes the document's final paragraph mark.
' Determine whether selection includes final
paragraph mark
Dim
SelectionIncludesFinalParagraphMark As Boolean
If Selection.Type =
wdSelectionNormal _
And Selection.End =
ActiveDocument.Content.End _
Then
SelectionIncludesFinalParagraphMark =
True
When Word's Insertion Point is flashing in a document, the Selection
object's Start and End properties are equal to each other and represent how
many items are to the left of the Insertion Point. Since the Insertion Point
can travel up to but never past the final paragraph mark in a document, the
Start and End properties of the Selection object will never get higher than the
Start value of the final paragraph mark, which is to say, one less than the End
property of the final paragraph mark.
The following code takes advantage of this to determine whether the
insertion point is flashing in front of the document's final paragraph mark.
' Determine whether insertion point is
flashing at end of document
Dim
InsertionPointFlashingAtEndOfDoc As Boolean
If Selection.Type =
wdSelectionIP _
And Selection.End =
ActiveDocument.Content.End - 1 _
Then
InsertionPointFlashingAtEndOfDoc =
True
|