Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Word Solutions
 How to: Set Search Options in Word

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Microsoft Visual Studio Tools for the Microsoft Office system (version 3.0)
How to: Set Search Options in Word

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Project type

  • Document-level projects

  • Application-level projects

Microsoft Office version

  • Word 2003

  • Word 2007

For more information, see Features Available by Application and Project Type.

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

  • Set individual properties of a Find object.

  • Use arguments of the Execute method of a Find object.

The following code sets properties of a Find object to search for text within the current 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 you write C# code because you must specify the same properties as parameters in the Execute method. Therefore this example contains only Visual Basic code.

To set search options using a Find object

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

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

The following code uses the Execute method of a Find object to search for text within the current 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.

    Visual Basic
    With Application.Selection.Find
        .ClearFormatting()
        .Execute(FindText:="find me", Forward:=True, Wrap:=Word.WdFindWrap.wdFindContinue)
    End With
    
    
    C#
    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);
    
    
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker