HotKey/Macro that quotes current word

  • Thread starter Thread starter livetohike
  • Start date Start date
L

livetohike

Is there a way to quickly put double quotes around the current word?

I would like a macro that will look at the current insertion point,
and if it is a word insert quotes at the beginning and end of the word.
 
If you *never* have need to put the quotes around more than one word it
might be worth your while to have a macro with a keystroke assigned.
Otherwise you'd need a separate macro for a 2-word string, a 3-word string,
etc. Why not try this - I find it just as convenient:

Start at the *right end* of the word/string type your " then hit
Option+LeftArrow as many times as necessary (once per word) & type your
closing ". [Note: Unfortunately doesn't work as well in the opposite
direction because it grabs the ending space.]

HTH |:>)
Bob Jones
[MVP] Office:Mac
 
What's "Option+LeftArrow"? Must be a Mac thing. :-)

If you don't mind selecting what you want quoted (be it a word, phrase,
etc.), the following macro will put [smart] quotes around the selection:

Sub QuoteIt()
Selection.Copy
Selection.TypeText Text:=Chr$(147) + Chr$(148)
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Paste
Selection.MoveRight Unit:=wdCharacter, Count:=1
End Sub

I have this assigned to Ctrl+Alt+", and use it frequently.

--
Herb Tyson MS MVP
Author of the Word 2007 Bible
Blog: http://word2007bible.herbtyson.com
Web: http://www.herbtyson.com


CyberTaz said:
If you *never* have need to put the quotes around more than one word it
might be worth your while to have a macro with a keystroke assigned.
Otherwise you'd need a separate macro for a 2-word string, a 3-word
string,
etc. Why not try this - I find it just as convenient:

Start at the *right end* of the word/string type your " then hit
Option+LeftArrow as many times as necessary (once per word) & type your
closing ". [Note: Unfortunately doesn't work as well in the opposite
direction because it grabs the ending space.]

HTH |:>)
Bob Jones
[MVP] Office:Mac



Is there a way to quickly put double quotes around the current word?

I would like a macro that will look at the current insertion point,
and if it is a word insert quotes at the beginning and end of the word.
 
What's "Option+LeftArrow"? Must be a Mac thing. :-)
<snip>

Senior Disorientation strikes again - you're absolutely right:-)

In WinWord it's Control+LeftArrow.
 
What's "Option+LeftArrow"? Must be a Mac thing. :-)

If you don't mind selecting what you want quoted (be it a word, phrase,
etc.), the following macro will put [smart] quotes around the selection:

Sub QuoteIt()
Selection.Copy
Selection.TypeText Text:=Chr$(147) + Chr$(148)
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Paste
Selection.MoveRight Unit:=wdCharacter, Count:=1
End Sub

I have this assigned to Ctrl+Alt+", and use it frequently.

--
Herb Tyson MS MVP
Author of the Word 2007 Bible
Blog:http://word2007bible.herbtyson.com
Web:http://www.herbtyson.com


If you *never* have need to put the quotes around more than one word it
might be worth your while to have a macro with a keystroke assigned.
Otherwise you'd need a separate macro for a 2-word string, a 3-word
string,
etc. Why not try this - I find it just as convenient:
Start at the *right end* of the word/string type your " then hit
Option+LeftArrow as many times as necessary (once per word) & type your
closing ". [Note: Unfortunately doesn't work as well in the opposite
direction because it grabs the ending space.]
HTH |:>)
Bob Jones
[MVP] Office:Mac
On 8/16/07 4:28 PM, in article
(e-mail address removed), "livetohike"

Thanks Herb, that is a nice compromise. One addition would be nice.
Occasionally I accidentally invoke it when nothing is selected and it
throws a run time error on "Selection.Copy". It has been a very long
time since I code, but does VBA have an exception handling mechanism
to prevent this. Or a conditional that just returns when nothing is
selected?

BTW
Your solution got me thinking and I came up w/ the following one which
does not require the word to be selected, but has a problem when the
desired word comes at the end of sentence. See below:

test of quote at end of sentence.
With insertion point somewhere in the word sentence you get
"sentenc"e.

I see why. To get the quote in the right space for the normal case, I
need to backspace one character (to remove the ending space), but for
a word at end of sentence the backspace is not needed.

Thanks
 
What's "Option+LeftArrow"? Must be a Mac thing. :-)

If you don't mind selecting what you want quoted (be it a word, phrase,
etc.), the following macro will put [smart] quotes around the selection:

Sub QuoteIt()
Selection.Copy
Selection.TypeText Text:=Chr$(147) + Chr$(148)
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Paste
Selection.MoveRight Unit:=wdCharacter, Count:=1
End Sub

I have this assigned to Ctrl+Alt+", and use it frequently.

--
Herb Tyson MS MVP
Author of the Word 2007 Bible
Blog:http://word2007bible.herbtyson.com
Web:http://www.herbtyson.com

Thanks Herb, that is a nice compromise. One addition would be nice.
Occasionally I accidentally invoke it when nothing is selected and it
throws a run time error on "Selection.Copy". It has been a very long
time since I code, but does VBA have an exception handling mechanism
to prevent this. Or a conditional that just returns when nothing is
selected?

BTW
Your solution got me thinking and I came up w/ the following one which
does not require the word to be selected, but has a problem when the
desired word comes at the end of sentence. See below:

test of quote at end of sentence.
With insertion point somewhere in the word sentence you get
"sentenc"e.

I see why. To get the quote in the right space for the normal case, I
need to backspace one character (to remove the ending space), but for
a word at end of sentence the backspace is not needed.

Thanks

It is possible to use error trapping -- put the statement

On Error GoTo Bye

before the Selection.Copy, and put the "statement label"

Bye:

just before the End Sub. However, there's a better way, which not only
avoids this error, but prevents the macro from putting quotes around a
graphic or some other non-text selection. Put the statement

If Selection.Type = wdSelectionNormal Then

before the Selection.Copy, and put the statement

End If

just before the End Sub.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
I seldom use error trapping for my own macros (keep forgetting that tastes
vary)... I like being reminded that what I'm using is a macro rather than a
built-in command. Go figure... For stuff I write for clients, however, I
usually include trapping just so it's less abrasive. That one, I copied from
my VBA module without thinking about the fact that trapping was absent.

--
Herb Tyson MS MVP
Author of the Word 2007 Bible
Blog: http://word2007bible.herbtyson.com
Web: http://www.herbtyson.com


Jay Freedman said:
What's "Option+LeftArrow"? Must be a Mac thing. :-)

If you don't mind selecting what you want quoted (be it a word, phrase,
etc.), the following macro will put [smart] quotes around the selection:

Sub QuoteIt()
Selection.Copy
Selection.TypeText Text:=Chr$(147) + Chr$(148)
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Paste
Selection.MoveRight Unit:=wdCharacter, Count:=1
End Sub

I have this assigned to Ctrl+Alt+", and use it frequently.

--
Herb Tyson MS MVP
Author of the Word 2007 Bible
Blog:http://word2007bible.herbtyson.com
Web:http://www.herbtyson.com

Thanks Herb, that is a nice compromise. One addition would be nice.
Occasionally I accidentally invoke it when nothing is selected and it
throws a run time error on "Selection.Copy". It has been a very long
time since I code, but does VBA have an exception handling mechanism
to prevent this. Or a conditional that just returns when nothing is
selected?

BTW
Your solution got me thinking and I came up w/ the following one which
does not require the word to be selected, but has a problem when the
desired word comes at the end of sentence. See below:

test of quote at end of sentence.
With insertion point somewhere in the word sentence you get
"sentenc"e.

I see why. To get the quote in the right space for the normal case, I
need to backspace one character (to remove the ending space), but for
a word at end of sentence the backspace is not needed.

Thanks

It is possible to use error trapping -- put the statement

On Error GoTo Bye

before the Selection.Copy, and put the "statement label"

Bye:

just before the End Sub. However, there's a better way, which not only
avoids this error, but prevents the macro from putting quotes around a
graphic or some other non-text selection. Put the statement

If Selection.Type = wdSelectionNormal Then

before the Selection.Copy, and put the statement

End If

just before the End Sub.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
What's "Option+LeftArrow"? Must be a Mac thing. :-)
If you don't mind selecting what you want quoted (be it a word, phrase,
etc.), the following macro will put [smart] quotes around the selection:
Sub QuoteIt()
Selection.Copy
Selection.TypeText Text:=Chr$(147) + Chr$(148)
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Paste
Selection.MoveRight Unit:=wdCharacter, Count:=1
End Sub
I have this assigned to Ctrl+Alt+", and use it frequently.
--
Herb Tyson MS MVP
Author of the Word 2007 Bible
Blog:http://word2007bible.herbtyson.com
Web:http://www.herbtyson.com
Thanks Herb, that is a nice compromise. One addition would be nice.
Occasionally I accidentally invoke it when nothing is selected and it
throws a run time error on "Selection.Copy". It has been a very long
time since I code, but does VBA have an exception handling mechanism
to prevent this. Or a conditional that just returns when nothing is
selected?
BTW
Your solution got me thinking and I came up w/ the following one which
does not require the word to be selected, but has a problem when the
desired word comes at the end of sentence. See below:
test of quote at end of sentence.
With insertion point somewhere in the word sentence you get
"sentenc"e.
I see why. To get the quote in the right space for the normal case, I
need to backspace one character (to remove the ending space), but for
a word at end of sentence the backspace is not needed.

It is possible to use error trapping -- put the statement

On Error GoTo Bye

before the Selection.Copy, and put the "statement label"

Bye:

just before the End Sub. However, there's a better way, which not only
avoids this error, but prevents the macro from putting quotes around a
graphic or some other non-text selection. Put the statement

If Selection.Type = wdSelectionNormal Then

before the Selection.Copy, and put the statement

End If

just before the End Sub.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ:http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

OK, this is looking pretty good now.
I now I am getting bit greedy, but ...
Sometimes I make a mistake (can you believe that) and want to 'undo'
the quoting. Instinct has me 'Undo' (Ctrl-Z) and go on typing. But
the undo cuts the selection leaving a pair of quotes (""). A second
undo 'undo' is required to replace the quotes w/ the original selected
word. Looking at the code I understand why this happens, but of
course the macro makes it feel like a single action, and a single undo
would be really nice. Not sure if this is asking two much of VBA, but
thanks a heap either way.
 

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

Back
Top