Finding and Replacing Text
The ability to find text and/or formatting in a document, and optionally replace it, is an important part of many custom Office solutions. When using the Word application directly, you use the Find and the Find and Replace dialog boxes to perform these tasks. In a VBA program, the Find object provides the same functionality as these dialog boxes.
Both the Selection object and the Range object have a Find property that provides a reference to a Find object that you can use with that selection or range. The general procedure is as follows:
Listing 0 Define a selection or, more often, a range that includes the part of the document you want to search.
Listing 1 Set the Find object's properties to specify the search details. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access