View Single Post
  #6   Report Post  
Posted to microsoft.public.word.docmanagement
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default HotKey/Macro that quotes current word

On Sun, 26 Aug 2007 14:54:12 -0000, livetohike
wrote:

On Aug 16, 8:15 pm, "Herb Tyson [MVP]" wrote:
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 FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.