Share via


Document.Find Property

Publisher Developer Reference

Returns a FindReplace object. The FindReplace object is used to perform a text search and replace in the specified document.

Syntax

expression.Find

expression   A variable that represents a Document object.

Example

As it applies to the Document object.

The following example sets an object variable to the FindReplace object of the active document. A search operation is executed that applies bold formatting to every occurrence of the word "important".

Visual Basic for Applications
  Dim objFind as FindReplace
Dim fFound as Boolean

Set objFind = ActiveDocument.Find fFound = True

With objFind .Clear .FindText = "important" Do While fFound = True fFound = .Execute If Not .FoundTextRange Is Nothing Then .FoundTextRange.Font.Bold = True End If Loop End With

As it applies to the TextRange object.

The following example sets an object variable to the FindReplace object of the text range of the first shape in the active document. A search operation is executed that applies bold formatting to every occurrence of the word "urgent" in the text range.

Visual Basic for Applications
  Dim objFind as FindReplace
Dim fFound as Boolean

Set objFind = ActiveDocument.Pages(1) _ .Shapes(1).TextFrame.TextRange.Find fFound = True

With objFind .Clear .FindText = "urgent" Do While fFound = True fFound = .Execute If Not .FoundTextRange Is Nothing Then .FoundTextRange.Font.Bold = True End If Loop End With

See Also