查找对象 (Word)Find object (Word)

代表查找操作的执行条件。Represents the criteria for a find operation.

说明Remarks

Find 对象的属性和方法对应于" 查找和替换"对话框中的选项。The properties and methods of the Find object correspond to the options in the Find and Replace dialog box.

使用 Find 属性返回 Find 对象。Use the Find property to return a Find object. 下例查找并选择出现的下一个"hi"单词。The following example finds and selects the next occurrence of the word "hi."

With Selection.Find 
 .ClearFormatting 
 .Text = "hi" 
 .Execute Forward:=True 
End With

以下示例在活动文档中查找所有“hi”并将其替换为“hello”。The following example finds all occurrences of the word "hi" in the active document and replaces the word with "hello."

Set myRange = ActiveDocument.Content 
myRange.Find.Execute FindText:="hi", ReplaceWith:="hello", _ 
 Replace:=wdReplaceAll

注解Remarks

如果你已从 Selection 对象中获得 Find 对象,当发现文本与下一个查找条件匹配时,所选内容会更改。If you've gotten to the Find object from the Selection object, the selection is changed when text matching the find criteria is found. 下例选择出现的下一个"blue"单词。The following example selects the next occurrence of the word "blue."

Selection.Find.Execute FindText:="blue", Forward:=True

如果你已从 Range 对象中获得 Find 对象,当发现文本与下一个查找条件匹配时,所选内容不会更改,但将重新定义 Range 对象。If you've gotten to the Find object from the Range object, the selection isn't changed when text matching the find criteria is found, but the Range object is redefined. 下例在活动文档中查找出现的第一个“blue”单词。The following example locates the first occurrence of the word "blue" in the active document. 如果在文档中找到“blue”,则将重新定义 myRange,“blue”将应用粗体格式。If "blue" is found in the document, myRange is redefined and bold formatting is applied to "blue."

Set myRange = ActiveDocument.Content 
myRange.Find.Execute FindText:="blue", Forward:=True 
If myRange.Find.Found = True Then myRange.Bold = True

另请参阅See also

Word 对象模型参考Word Object Model Reference

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.