Word

Add Quotation Marks To Selected Text

Ease of Use

Easy

Version tested with

2003 

Submitted by:

lucas

Description:

Add quotation marks to a single word or a selection of text. 

Discussion:

Sometimes we forget our quotation marks as we type. With this macro assigned to a shortcut key combination or a button you can simply select the text and run the macro and the selection is enclosed in quotation marks. The macro determines the proper type of quote marks to use, based on whether you have Word's SmartQuotes turned on or not. The proper quotes are then placed before and after the selection. 

Code:

instructions for use

			

Place the following code In a standard module: Option Explicit Sub addquotes() Dim r As Range With ActiveDocument 'check for extra spaces and punctuation & 'select the entire word or phrase Set r = Selection.Words(Selection.Words.Count) If r.Characters(r.Characters.Count) = " " Then Set r = .Range(Selection.Words(1).Start, _ Selection.Words(Selection.Words.Count).End - 1) Else Set r = .Range(Selection.Words(1).Start, r.End) End If 'check to see if AutoformatasYouType is being used If Options.AutoFormatAsYouTypeReplaceQuotes Then r.InsertBefore Chr(147) r.InsertAfter Chr(148) Else r.InsertBefore Chr(34) r.InsertBefore Chr(34) End If End With ' select the results as reference...can be commented if not needed r.Select End Sub

How to use:

  1. Open the Visual Basic Editor by going to Tools-Macros-Visual Basic Editor or use Alt-F11
  2. On the toolbar of the Visual Basic Editor, go to insert - module
  3. In the module pane paste the code above.
  4. Close the Visual Basic Editor by clicking the X in the upper right corner or go to File-Close
 

Test the code:

  1. Select some text on your word document.
  2. On the main menu go to tools-macro-macros.
  3. In the dialog window select addquotes and then click run.
 

Sample File:

put quotes around selection.zip 7.78KB 

Approved by mdmackillop


This entry has been viewed 94 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express