Word 2004 Tip: Adding a ‘Find Previous’ command to Word’s text searching features
Posted by Pierre Igot in: MacintoshJune 10th, 2004 • 5:08 am
Last week I mentioned my struggles with locating the “Find Next” command in Word’s totally inconsistent interface. I finally managed to assign the command-G shortcut to it.
Today I want to take things one step further.
Because I often hit my “EditFindPrevious
” command or anything like that.
So I decided to create a macro for this. Word’s “Find” dialog box has a pop-up menu that lets you change the orientation of the search. You can go forward (i.e. down) in a document (which is the default orientation), but you can also go backward (i.e. up), by changing the setting to “
” in the “Find” dialog box (you need to expand the dialog box to display extra options first, and then use the first pop-up menu that appears in the expanded section).Usually most options that are available through dialog boxes in Word can also be accessed directly in a macro command using Visual Basic, without actually asking the user to go through the dialog box manually.
It took me a little while to figure out exactly which command it was, because Word’s Help feature is so hopeless, and of course the setting is not called the same in Visual Basic as it is in the Word user interface, but I finally figured it out. I created the following macro:
Sub FindPrevious() With Selection.Find .Forward = False .Execute .Forward = True End With End Sub
The “.Forward = False
” line is to change the orientation of the search (the opposite of forward being backward), the “.Execute
” line simply repeats the last Find command, and the “.Forward = True
” line is to change the orientation back to the default (forward) for the next search.
I assigned the command-shift-G shortcut to this macro and tried it out. It worked, except that I found that, after using command-shift-G, I had to press command-G twice to get it going in the forward direction again. Don’t ask me why!
But I found a way to eliminate that problem too. Instead of using Word’s built-in “RepeatFind
” command for finding the next occurrence, I decided to write my own little macro that does the same thing:
Sub FindNext() With Selection.Find .Forward = True .Execute End With End Sub
I assigned the command-G shortcut to this macro instead of the “RepeatFind
” command — et voilà! I no longer have to hit command-G twice to get things going in the right direction again.
June 10th, 2004 at Jun 10, 04 | 10:48 am
How about an equivalent of “Use Selection for Find” (command-E) that’s in just about every other Mac program out there? I saw no built-in function for that, looks like you’d have to write a Macro for this as well. And THEN get it to use the shared Find pasteboard – that would be useful. But Word seems to be an island – no Serivces (Entourage 2004 supports them) support, either.
June 11th, 2004 at Jun 11, 04 | 12:36 am
yes, “Use Selection for Find” would require a macro — it probably wouldn’t be too complicated. I might give it a try one of these days.
As for the “Find pasteboard”, I must admit I have no idea what you are referring to. What is this?
But I do agree that Word is an island when it comes to support for standard Mac OS X features such as services… Remember that this is how the whole discussion between me and Rick Schaut a while back got started: lack of support for Mac OS X’s built-in spell checker in Word. Rick’s argument is that the user demand for this is low. But then he says that Microsoft establishes this by doing a user survey asking “Would you like support for Mac OS X’s Services in Office?” Of course, if they’d asked “Would you like to only have one set of spell checking dictionaries to manage for all your Mac OS X applications, including Word?”, they probably would have gotten a different answer. Anyway…
June 12th, 2004 at Jun 12, 04 | 4:34 pm
Aha! I had not bothered to register on your site, so I wasn’t seeing the pMcode link. It just had the info about maximum characters.
I am now, so I see the pMcode link.
June 12th, 2004 at Jun 12, 04 | 2:55 am
Evan: Thanks for the clarification about the Find pasteboard. I was intuitively aware that there was something like that in Mac OS X, because I had noticed on occasion that the search string from one application was also used by default in another application. I guess I didn’t realize it was a feature with a name :).
No hope of writing a macro to make Word aware of it, though, I am afraid.
June 12th, 2004 at Jun 12, 04 | 2:52 am
Patrick: Below the “Add your own comment” field there is a line that reads “(Maximum 4000 characters. You may use pMcode in your entries.)” I should probably give the list of pMcode tags instead. When I get around to it :).
June 11th, 2004 at Jun 11, 04 | 3:15 pm
Pierre, glad you liked the macro. I don’t use Office on my home Mac, but I would be lost without macros in Office on my Windows machine at work.
BTW, I don’t see any such link at the bottom of the page. I checked in Firefox and IE5.something on my work PC and in Safari on my home Mac.
June 11th, 2004 at Jun 11, 04 | 4:05 am
Patrick: Thanks! See “Word 2004 Tip: Adding a ‘Find With Selection’ command to Word’s text searching features“.
For future reference, you may use pMcode in your comments, including the PRE tag (with square brackets) for preformatted code. See the link below the “Add your own comment” field at the bottom of this page.
June 11th, 2004 at Jun 11, 04 | 9:58 am
The Find pasteboard:
Do a command-E in Mail.app.
Switch to TextEdit (or just about any other OS X app that has a Find window). Command-F.
Notice that what you told Mail to search for is already in the TextEdit Find window. This is because there is a shared Find pasteboard that all apps can (and should) use.
June 11th, 2004 at Jun 11, 04 | 2:09 am
Here’s a “Use Selection for Find” type macro I wrote for WinWord:
Public Sub FindSelection()
‘created: 03/22/03 PTW
Dim seltext As String
‘get selection text without start/end spaces
seltext = Trim(Selection.Text)
‘we want to start our search after current selection
‘(otherwise the first found instance will be the selected text!)
Selection.Collapse wdCollapseEnd
‘now, find!
With Selection.Find
.ClearFormatting
.Text = seltext
.Forward = True
.Wrap = wdFindStop ‘don’t wrap to top
.Execute
End With
End Sub
It should be pretty much the same on MacWord, I would imagine.
(Ugh, on preview that looks nasty, but I couldn’t figure out how to format it in a comment. Sorry.)
The “Find Pasteboard” is the ability of Cocoa apps (and maybe Carbon too, if the app supports it; I’m unsure about this, though) to share find terms. Search for “Harvard” in Safari, for instance, and the next search you do in TextEdit will already have the string “Harvard” in the Find dialog.
June 12th, 2004 at Jun 12, 04 | 11:24 pm
Patrick: My turn to say “Aha!” I didn’t realize that the pMcode link was not there in the form for unregistered members. An oversight on my part. It’s been corrected. Thanks! :)