FindReplace object (Publisher)
Represents the criteria for a find operation. The properties and methods of the FindReplace object correspond to the options in the Find and Replace dialog box.
Remarks
When the ReplaceScope property is set to one of the PbReplaceScope constants pbReplaceScopeOne or pbReplaceScopeAll, the ReplaceWithText property must be set to avoid the text from being replaced with the default value of an empty String for that property.
Use the TextRange.Find property to return a FindReplace object.
Set the ReplaceScope property to determine the extent of the search.
Example
The following example selects the next occurrence of the word factory.
With ActiveDocument.Find
.Clear
.FindText = "factory"
.Execute
End With
The following example replaces the first occurrence of the name Visual Basic Scripting Edition with VBScript.
With ActiveDocument.Find
.Clear
.FindText = "Visual Basic Scripting Edition"
.ReplaceWithText = "VBScript"
.ReplaceScope = pbReplaceScopeOne
.Execute
End With
The following example illustrates how the font attributes of the FoundTextRange can be accessed when ReplaceScope is set to pbReplaceScopeNone.
Dim objFindReplace As FindReplace
Set objFindReplace = ActiveDocument.Find
With objFindReplace
.Clear
.FindText = "important"
.ReplaceScope = pbReplaceScopeNone
Do While .Execute = True
If .FoundTextRange.Font.Italic = msoFalse Then
.FoundTextRange.Font.Italic = msoTrue
End If
Loop
End With
Methods
Properties
- Application
- FindText
- Forward
- FoundTextRange
- MatchAlefHamza
- MatchCase
- MatchDiacritics
- MatchKashida
- MatchWholeWord
- MatchWidth
- Parent
- ReplaceScope
- ReplaceWithText
See also
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.