Document.Find property (Publisher)

Returns a FindReplace object from the specified Document 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

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.

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 

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.

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

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.