CmpBookmarks()

Syntax

CmpBookmarks(Bookmark1$, Bookmark2$)

Remarks

Compares the contents of two bookmarks. Use CmpBookmarks() with the predefined bookmarks in Word to check the location of the insertion point or to create a macro that operates only within an area marked with a bookmark. For example, using the "\ Sel" (current selection) bookmark and the "\ Para" bookmark, you can set up a macro to operate only within a particular paragraph. For more information about predefined bookmarks, see "Operators and Predefined Bookmarks" later in this part.

Argument

Explanation

Bookmark1$

The first bookmark

Bookmark2$

The second bookmark


This function returns the following values.

Value

Explanation

0 (zero)

Bookmark1$ and Bookmark2$ are equivalent.

1

Bookmark1$ is entirely below Bookmark2$.

2

Bookmark1$ is entirely above Bookmark2$.

3

Bookmark1$ is below and inside Bookmark2$.

4

Bookmark1$ is inside and above Bookmark2$.

5

Bookmark1$ encloses Bookmark2$.

6

Bookmark2$ encloses Bookmark1$.

7

Bookmark1$ and Bookmark2$ begin at the same point, but Bookmark1$ is longer.

8

Bookmark1$ and Bookmark2$ begin at the same point, but Bookmark2$ is longer.

9

Bookmark1$ and Bookmark2$ end at the same place, but Bookmark1$ is longer.

10

Bookmark1$ and Bookmark2$ end at the same place, but Bookmark2$ is longer.

11

Bookmark1$ is below and adjacent to Bookmark2$.

12

Bookmark1$ is above and adjacent to Bookmark2$.

13

One or both of the bookmarks do not exist.


Example

This example adds a string of characters in front of every line in a selection.
The example first marks the selected text with a bookmark and then uses a While¼Wend loop controlled by three CmpBookmarks() functions to add text in front of each line. The first CmpBookmarks() function tests whether the insertion point and the selection, stored in the "Temp" bookmark, begin at the same point; this is true when the loop begins. The second CmpBookmarks() function tests whether the insertion point is contained within "Temp"; this is true as long as the insertion point is within the original selection. The third CmpBookmarks() function tests whether the insertion point is at the end of the original selection. When the insertion point moves beyond the original selection, the loop ends. Within the While¼Wend loop is yet another CmpBookmarks() instruction, which determines whether the selection is at the end of the document, a special case.


CopyBookmark "\Sel", "Temp"
SelType 1
While CmpBookmarks("\Sel", "Temp") = 8 \
        Or CmpBookmarks("\Sel", "Temp") = 6 \
        Or CmpBookmarks("\Sel", "Temp") = 10 \
        And leaveloop <> 1
    EndOfLine
    If CmpBookmarks("\Sel", "\EndOfDoc") = 0 Then leaveloop = 1
    StartOfLine
    Insert "***"
    LineDown
Wend
EditGoTo "Temp"
EditBookmark "Temp", .Delete

See Also

CopyBookmark, EditBookmark, EmptyBookmark