This documentation is archived and is not being maintained.

Bookmark.MoveUntil Method (Object, Object)


Moves the Bookmark control until one of the specified characters is found in the document.

Namespace:   Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word (in Microsoft.Office.Tools.Word.dll)

int MoveUntil(
	ref object cset,
	ref object count


Type: System.Object

One or more characters. If any character in Cset is found before the Count value expires, the Bookmark control is positioned as an insertion point immediately before that character. This argument is case sensitive.

Type: System.Object

The maximum number of characters by which the Bookmark control is to be moved. Can be a number or either the F:Microsoft.Office.Interop.Word.WdConstants.wdForward or F:Microsoft.Office.Interop.Word.WdConstants.wdBackward constant. If Count is a positive number, the Bookmark control is moved forward in the document, beginning at the end position. If it is a negative number, the Bookmark control is moved backward, beginning at the start position. The default value is F:Microsoft.Office.Interop.Word.WdConstants.wdForward.

Return Value

Type: System.Int32

The number of characters by which the Bookmark control was moved. If Count is greater than 0 (zero), this method returns the number of characters moved plus one. If Count is less than 0 (zero), this method returns the number of characters moved minus one. If no Cset characters are found, the Bookmark control is not changed and the method returns 0 (zero).

The Bookmark is collapsed to a zero-length bookmark.

For information on optional parameters, see Optional Parameters in Office Solutions.

The following code example adds a Bookmark control with text to the first paragraph and then adds another Bookmark control to the third word in the first bookmark. The code then moves the range of the second bookmark while it can find a blank space.

This example is for a document-level customization.

private void BookmarkMoveUntil()
    Microsoft.Office.Tools.Word.Bookmark bookmark1 =
    bookmark1.Text = "This is sample bookmark text.";

    Microsoft.Office.Tools.Word.Bookmark bookmark2 =

    object Count = bookmark1.Characters.Count;
    object cSet = " ";

    bookmark2.MoveUntil(ref cSet, ref Count);
Return to top