Gold and blue bar

Basic Concepts - Introduction

Understanding styles

Tips for understanding styles in Microsoft Word

How to apply a style

How to modify a style

How styles in Word cascade

Why does Word sometimes override bold and italics when I apply a paragraph style, but sometimes it does not?

Why I don't use Custom Table Styles

Keep a figure on the same page as its caption

Is your image slipping? How to get your images to stand still

Create a glossary

How the Styles and Formatting Pane works

Why does text change format when I copy it into another document?

How Paste Options works

Letters are missing in my watermark when I print

How to tell Word to use Australian English or other non-US form of English

Control bullets

Create numbered headings

Number headings and figures in Appendixes

Why use Word's built-in heading styles?

Create a table of contents

How Document Map works

Relationship between documents and templates

Attaching a template to a document

How to copy a chart from Excel into a Word document

Insert an Excel chart or worksheet into a landscape page

How to create a hyperlink from a Word document to an Excel workbook

What happens when I send my document to someone else?

How does Track Changes work?

How to use the Reviewing Toolbar in Microsoft Word 2002 and Word 2003

Control how a Word document opens from the internet or an intranet

CompleteWordCount

How to get Word to automatically fill the Edit > Find and Edit > Replace boxes with the selected text

Office 2007 information

Trivia

Contents of this site

Getting help, asking questions

Search Google
Search WWW
Search www.ShaunaKelly.com

www.ShaunaKelly.com

Contact

Word

How to get Word to automatically fill the Edit > Find and Edit > Replace boxes with the selected text

Quick Reference

Quick Reference: Copy the macro on this page into your normal.dot file or an add-in file

Word will then default the 'find' text to your selected text.

When you do Edit > Find or Edit > Replace, Word remembers the text you went to 'Find' last time.

This is almost never what I want.

I'd like Word to default the 'Find' text to the text I've selected in the document.

So, I wrote two little macros to do the job.

How to use the macros

Just do Edit > Find (or ctrl-f), or Edit > Replace (or ctrl-h) as usual. These macros replace the existing commands, so they kick in automatically.

The text you select will be automatically inserted into the 'Find' text box on the Edit > Find or Edit > Replace dialog boxes, as shown below:

Default the selected text

Figure 1: When you use these macros, Word will automatically default the 'Find' text to the text you have selected in the document.

If you select text in a numbered paragraph, copy it, and paste it into the Edit > Find or Edit > Replace dialogs, Word pastes the heading numbering along with the text.

That's very annoying.

Using these macros avoids that problem, because it just pastes the textnot the numbering!

How the macros work

The macros intercept the existing commands as described at:
Intercepting events like Save and Print http://www.word.mvps.org/FAQs/MacrosVBA/InterceptSavePrint.htm

Beware the trailing space!

If you double-click a word, then Word automatically selects the space after the word, if there is one. Like this:

Selecting a word by double-clicking includes the trailing space in the selection

Figure 2: When you double-click to select a Word, word automatically selects the trailing space.

These macros trim that trailing space. If you use these macros, the default 'Find' text will be "brown", not "brown ". If you need to search for "brown ", then you'll need to add the extra space.

How to install the macros

1. Look at the following for information on how to use the macros:

2. Copy and paste the code of the macros at the end of this page.

Text of the macros

Here is the code you need to copy into your file:

Public Sub EditFind()
'Shauna Kelly, www.ShaunaKelly.com, 2006.
'A replacement for the Edit > Find dialog that
'defaults the 'Find' text to the currently selected
'text.


On Error Resume Next

With Dialogs(wdDialogEditFind)
    If Not Selection.Start = Selection.End Then
        'If the user has selected some text, use that
        'text as the default for the Edit > Find
        'dialog box.

        .Find = Trim(Selection.Text)
    End If

    'And show the Edit > Find dialog box as normal
    .Show
End With

End Sub


Public Sub EditReplace()
'Shauna Kelly, www.ShaunaKelly.com, 2006.
'A replacement for the Edit > Find dialog that
'defaults the 'Find' text to the currently selected
'text.


On Error Resume Next

With Dialogs(wdDialogEditReplace)
    If Not Selection.Start = Selection.End Then
        'If the user has selected some text, use that
        'text as the default for the Edit > Replace
        'dialog box

        .Find = Trim(Selection.Text)
    End If

    'And show the Edit > Replace dialog box as normal
    .Show
End With

End Sub