Find and Replace

M

Maria

How do I--using Find and Replace--place quotation marks
around a selected word or group of words? When I select a
group of words my attempts have produced either EACH word
in quotes or TWO words in quotes, not the whole phrase.
I'm sure I'm overlooking something simple. Thanks for
always being there!
 
M

Mark Tangard

Hi Maria,

I don't think that's possible to do with Find/Replace, since
there's no way to refer, in that dialog, to the text that's
selected in the document.

But I craved the same capability, came up with the macro below
to do it, and assigned it to a keyboard shortcut, so now I can
quote whatever's selected with one keystroke.

The macro quotes whatever's selected (shrinking it first if it
ends in a space so you don't have to do that yourself). Or if
nothing's selected, it quotes the preceding word.

See also:

http://www.mvps.org/word/FAQs/MacrosVBA/CreateAMacro.htm
for how to use macros offered in newsgroup postings

and

http://www.mvps.org/word/FAQs/MacrosVBA/AssignMacroToHotkey.htm
for how to assign a macro to a hotkey

Here's the macro:

Sub QuoteSelectionOrPrecedingWord()
If Documents.Count = 0 Then Exit Sub
If Selection.End - Selection.Start = 0 Then
With Selection
.Collapse wdCollapseEnd
Do Until .Characters.first.Previous.Text <> " "
.MoveLeft wdCharacter, 1
Loop
.InsertAfter Chr$(148)
.MoveLeft wdWord, 2
.InsertAfter Chr$(147)
.MoveRight wdCharacter, 1
.MoveRight wdWord, 1
.MoveRight wdWord, 1
End With
Else
With Selection
.InsertBefore Chr$(147)
If .Characters.Last.Text = " " Then _
.MoveEnd wdCharacter, -1
.InsertAfter Chr$(148)
.Collapse wdCollapseEnd
End With
End If
End Sub

This inserts 'curly quotes'; if you want the plain vanilla
quotes, substitute 34 for the 147 and 148 above.
 
S

Suzanne S. Barnhill

How are you searching for the words? Using specific strings or some sort of
formatting? If the former, you should be able to use "^&" as the replacement
text.

Interestingly, if I search for bold text ("Find what" empty but Format:
Bold) and replace it with "^&", I get quotes around each bold phrase (not
individual words), but I get opening quotes instead of closing quotes at the
end even when the found string does not include a space at the end. Very
curious!

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
Word MVP FAQ site: http://www.mvps.org/word
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
M

Maria

Hi Mark,

I like your word "craved" because I'm just now at the
stage where I crave the knowledge you guys have about VBA
and really don't know where to start except for the
wonderful articles I read on the MVP site.

I can't wait to try your macro, Mark! First, however, I
will reread the MVP how-to article on how to store the
macro. Thanks more than I can say!
 
M

Maria

Hi Suzanne,

Thanks, more than words can say, Suzanne. You're always
right there and right on! Every stupid mistake I make just
causes me to be more determined than ever to learn more
about the suject.

I'm really new to this, so don't laugh when I tell you
that I was just selecting the word or phrase and entering
in the Find What box all the word-finding combinations
that are in my presently anemic toolbox, such as (<*>@)or
(<*@)([! ]*>)and quotation marks with the corresponding
expression indicators in the Replace With box. I did
stumble across one that would put quotes around one word,
but only if I started the selection one space before the
word.

Thanks again, Suzanne!
 
K

Klaus Linke

Interestingly, if I search for bold text ("Find what" empty but
Format: Bold) and replace it with "^&", I get quotes around each
bold phrase (not individual words), but I get opening quotes
instead of closing quotes at the end even when the found string
does not include a space at the end. Very curious!


Hi Suzanne,

"Find/Replace" seems still pretty buggy to me, even after 10 versions.

If the selection is part bold and part not bold, and I search downwards
(for bold, "Find what" empty), only the bold stuff in the selection will be
replaced.
But if all the selection is bold, Word will replace bold text in the whole
document.
The latter may be "by design", but I sure wouldn't have expected it...

That Word puts in the wrong type of quotes probably is another bug.

Another similar annoyance (Word2000):

If I select the sentence "This is a test.", and replace "is" with something
else, only the word "is" in the selection is replaced.

But if I just select the word "test" and replace "e" with something else,
Word replaces all "e" in the whole document.

Searching with "Match wildcards" has similar problems.

Regards,
Klaus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Find and Replace 2
find and replace using wildcard characters 2
How do I quickly add quotation marks? 2
Find and Replace 7
Find and Replace 3
Find and Replace 5
Insert instead of replace 2
Find Replace 3

Top