Execute FindText:="", ReplaceWith:="", _ The selection remains unchanged because the Find object is accessed from a Range object (the Content property returns a Range object). To find and replace formatting, set the find and replace text to empty strings ("") and set the Format argument of the Execute method to True. The Bold property is True for the Find object and False for the Replacement object. The following example removes bold formatting in the active document. Execute Replace:=wdReplaceAll, Forward:=True, _ The selection changes when the find criteria is found because the Find object is accessed from the Selection object. With so many formatting options readily available on the Ribbon, Find and Replace is a seldom-used, though powerful, alternative. The following example replaces all occurrences of the word "hi" with "hello".
Applies to: The information in this topic applies to document-level projects and VSTO Add-in projects. Use a Find object to loop through a Microsoft Office Word document and search for specific text, formatting, or style, and use the Replacement property to replace any of the items found. The Replacement object is available from the Find object. The replace command is an extension of the find command. The properties and methods of the Replacement object correspond to the options in the Find and Replace dialog box ( Edit menu). The Replacement object represents the replace criteria for a find and replace operation. The following example performs the same result as the previous example, using arguments of the Execute method. If the find operation is successful, the range is redefined and bold formatting is applied to the word "blue." With The following example locates the first occurrence of the word "blue" in the active document. If the Find object is accessed from a Range object, the selection is not changed but the Range is redefined when the find criteria is found. FindText:="Hello", _įinding text without changing the selection You can set the individual properties of the Find object or use arguments with the Execute method, as shown in the following example. The Find object includes properties that relate to the options in the Find and Replace dialog box. You can likewise use Find and Replace to locate particular types of format throughout your document and even change that formatting with something else. The following example selects the next occurrence of the word "Hello." If the end of the document is reached before the word "Hello" is found, the search is stopped. Microsoft Word’s Find and Replace function isn’t simply for changing text.
If the Find object is accessed from the Selection object, the selection is changed when the find criteria is found. The find action differs slightly depending upon whether you access the Find object from the Selection object or the Range object. (If you don’t understand HTML, don’t worry.
For example, let’s say you need to add the HTML italic tags and around anything formatted with italic.The Find object is available from the Selection object and the Range object. If you’re faced with a complex task using Microsoft Word’s Find and Replace feature, the Find What Text replacement code may come in handy. If you have styles that are more difficult to replace with simple keyboard shortcuts, you can click the “More” button on the lower left-hand side to show a lot more options.Finding and replacing is exposed by the Find and Replacement objects. You can even use multiple search criteria here. For instance, if you wanted to replace all bolded text with regular text, you’d use Ctrl+B in the “Find what” box, or for italics you would use Ctrl+I.
Open up the Find and Replace dialog from the menus, or just use the Ctrl+H keyboard shortcut.Ĭlick in the blank Find box, and then you can use the regular keyboard shortcuts to specify specific formatting. Or you could remove that ugly Heading 2 style they used… what were they thinking using bright red? You can easily search and replace all bolded or italicized text in a document, for instance. What you might not realize is that the search and replace functionality in Word allows you to replace more than just text. If you’ve ever worked on a document originally created by somebody else, you’ll most likely immediately be frustrated by their horrible choice of fonts and formatting.