Word 2004 Tip: Adding a ‘Find With Selection’ command to Word’s text searching features
Posted by Pierre Igot in: MacintoshJune 11th, 2004 • 4:01 am
Yesterday I posted a tip describing how to add a “ ” command to Word’s text searching user interface. In the comments on this item, Evan asked about a “ ” command similar to the one available in other Mac OS X applications (such as Mail). I suggested that it was probably possible with a macro. I was going to try it later on, but Patrick Wynne beat me to it and was kind enough to submit his own WinWord macro.
I tested his macro in Word 2004 and it worked fine. Here it is:
Sub FindWithSelection() ' ' FindWithSelection Macro ' Macro created 11/06/04 by Patrick Wynne ' 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
I called it “FindWithSelection
” rather than “UseSelectionForFind
” but that’s just for internal purposes when editing macro commands in Word. (I prefer it when similar commands appear together alphabetically in my list of macros.) You can always use the “ ” phrase when adding the command to Word’s “ ” menu with “ “.
Thanks Patrick!