# Bookmark.MoveWhile Method

Visual Studio 2013

Moves the Bookmark control while any of the specified characters are found in the document.

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

## Syntax

```int MoveWhile(
ref Object cset,
ref Object count
)
```

#### Parameters

cset
Type: System.Object

One or more characters. This argument is case sensitive.

count
Type: System.Object

The maximum number of characters by which the Bookmark control is to be moved. Can be a number or either the wdForward or 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 wdForward.

#### Return Value

Type: System.Int32
The number of characters by which the Bookmark control was moved. If no Cset characters are found, the Bookmark control is not changed and the method returns 0 (zero).

## Remarks

While any character in Cset is found, the Bookmark control is moved. The Bookmark is collapsed to a zero-length bookmark.

### Optional Parameters

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

## Examples

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 collapses and moves the second bookmark while it can find the characters b, o, o, or k.

This example is for a document-level customization.

```private void BookmarkMoveWhile()
{
this.Paragraphs[1].Range.InsertParagraphBefore();
Microsoft.Office.Tools.Word.Bookmark bookmark1 =
"bookmark1");
bookmark1.Text = "This is sample bookmark text.";

Microsoft.Office.Tools.Word.Bookmark bookmark2 =
"bookmark2");

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

bookmark2.MoveWhile(ref cSet, ref Count);
}
```