To do that we can use the asterisk to represent any character or set of characters. Why are we going to use a wildcard character in our search? Well, we’re looking for anything that begins with a pair of square brackets ( ]). MatchWildcards? That’s even easier: MacthWildcards simply tells the script that we’re going to use a wildcard character in our search. If the cursor was at the end of the document we’d probably set the Forward property to False, which would cause us to search the document backwards, from the current cursor position to the beginning of the document. We want to do that because the cursor is currently positioned at the start of the document. The Forward property, when True, tells the script to search the document from the current cursor position to the end of the document. The first two properties – Forward and MatchWildcards – are relatively easy to figure out. Before we can use the Find object, however, we need to configure three important properties, something we do here: = True As you might expect, the Find object is used for finding text in a Word document.
#Brackets text editor wildcard in search code#
That’s a good point: we do walk through the code in each and every Hey, Scripting Guy! column, don’t we? We just thought that saying we were going to do that would somehow make today’s column sound special.Īs it turns out, the Selection object (which, when created without any additional parameters, simply positions the cursor at the very beginning of the document) has a child object named Find. With that in mind, let’s walk you through the code and see if we can explain how it works.
Set objDoc = (“C:\Scripts\Test.doc”)Īdmittedly, parts of this script are a little odd-looking, most notably the line where we specify our search text. A script that searches a document for words in square brackets? As long as you’re willing to overlook all the false starts we ran into, well, then it wasn’t so bad after all: Set objWord = CreateObject(“Word.Application”) Kitchen floor? That looks great … as long as you don’t take a look under the refrigerator, mind you. New molding? Looks nice just don’t look in the garbage can and count the number of pieces that were cut in the wrong place. In our defense, in most cases we come up with a finished product that looks reasonably good. Search a Word document for words in square brackets? Hey, how hard could something like that be? Put new molding in the family room? Come on, you just saw some wood and nail it to the wall, right? New tile in the kitchen? Piece of cake. You know, one thing that seems to be true of the Scripting Guys is a willingness to do something even when they have no idea what it is they’re doing. I then need to save the words I find to a text file. Hey, Scripting Guy! How can I search a Word document for all the words in double brackets? For example, I need to find words like this: ].