RockyRoad said:
Just one problem though - because it trims the space (and doesn't re-add
it after the quote), you get this
Testing "the quote"macro
(a lack of space after the quote symbol)
Is that fixable?
This macro will auto-select either straight or smart quotes (depending
on your Tools/Autocorrect/"AutoFormat as you type" setting), and will
trim left and right spaces from the quoted text, while preserving the
spaces (e.g., if 'the quote ' is selected, the result will be '"the
quote" '). It also will put the right-quote before a paragraph mark if
the paragraph mark is the last character selected:
Public Sub QuoteSelectedText()
Dim sTemp As String
Dim sLQuote As String
Dim sRQuote As String
If Selection.Type = wdSelectionNormal Then
sTemp = Selection.Text
If Options.AutoFormatAsYouTypeReplaceQuotes Then
sLQuote = Chr(210)
sRQuote = Chr(211)
Else
sLQuote = Chr(34)
sRQuote = Chr(34)
End If
If Len(Trim(sTemp)) = 0 Then
sTemp = sLQuote & sTemp & sRQuote
Else
If Left(sTemp, 1) = " " Then
sTemp = Right(Space(Len(sTemp)) & sLQuote & _
LTrim(sTemp), Len(sTemp) + Len(sLQuote))
Else
sTemp = sLQuote & sTemp
End If
If Right(sTemp, 1) = " " Then
sTemp = Left(RTrim(sTemp) & sRQuote & _
Space(Len(sTemp)), Len(sTemp) + Len(sRQuote))
ElseIf Right(sTemp, 1) = vbCr Then
sTemp = Left(sTemp, Len(sTemp) - 1) & _
sRQuote & vbCr
Else
sTemp = sTemp & sRQuote
End If
End If
Selection.Text = sTemp
End If
End Sub