Events
May 19, 6 PM - May 23, 12 AM
Calling all developers, creators, and AI innovators to join us in Seattle @Microsoft Build May 19-22.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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.
Applies to: The information in this topic applies to document-level projects and VSTO Add-in projects for Word. For more information, see Features available by Office application and project type.
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.
Set the properties of a 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
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.
Pass search criteria as parameters of the Execute method to search forward through a selection for the text find me.
Events
May 19, 6 PM - May 23, 12 AM
Calling all developers, creators, and AI innovators to join us in Seattle @Microsoft Build May 19-22.
Register today