Export (0) Print
Expand All
Expand Minimize

How to: Set Search Options in Word

NoteNote

Some code examples in this topic use the this or Me keyword or the Globals class in a way that is specific to document-level customizations, or they rely on features of document-level customizations such as host controls. These examples can be compiled only if you have the required applications installed. For more information, see Features Available by Product Combination.

There are two ways to set search options for selections in Microsoft Office Word 2003 documents:

  • Set individual properties of the Find object.

  • Use arguments of the Execute method.

Using Properties of the Find Object

The following code sets properties of the Find object to search for text within a selection. Notice that the search criteria, such as searching forward, wrapping, and text to search for, are properties of the Find object.

Setting each of the properties of the Find object is not useful when using C# because you must specify the same properties as parameters in the execute method. Therefore this example only contains Visual Basic code.

To set search options using the Find object

  • Set the properties of the Find object to search forward through a selection for the text find me.

    With Application.Selection.Find
        .ClearFormatting()
        .Forward = True
        .Wrap = Word.WdFindWrap.wdFindContinue
        .Text = "find me"
        .Execute()
    End With
    
    

Using Execute Method Arguments

The following code uses the Execute method of the Find object to search for text within a selection. Notice that the search criteria, such as searching forward, wrapping, and text to search for, are passed as parameters of the Execute method.

To set search options using Execute method arguments

  • Pass search criteria as parameters of the Execute method to search forward through a selection for the text find me.

    object findText = "find me";
    object forward = true;
    object wrap = Word.WdFindWrap.wdFindContinue;
    
    Application.Selection.Find.ClearFormatting(); 
    
    Application.Selection.Find.Execute(
        ref findText, ref missing, ref missing, ref missing, ref missing, 
        ref missing, ref forward, ref wrap, ref missing, ref missing,
        ref missing, ref missing, ref missing, ref missing, ref missing);
    
    

See Also

Community Additions

ADD
Show:
© 2014 Microsoft