Every now and again I have to cut and paste text between MS Word and my Terminal Emulator. The problem is that the AutoFormat facility changes quotes to ‘Smart Quotes’ and hyphens to en-dashes.
So why don’t I turn AutoFormat off? Well I have but because the documents are shared the minute someone else opens them they’re changed back.
Click on "Tools -> AutoCorrect… -> AutoFormat As You Type" to turn this annoying feature off.
The solution was to write a Word macro to convert smart quotes back to regular quotes and en-dashes back to hyphens.
This is the source code.
Sub Quotefix()
With Selection.Find
' Take care of double quotes
.ClearFormatting
.Replacement.ClearFormatting
.Text = ChrW(8220)
.Replacement.Text = """"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
.Text = ChrW(8221)
.Replacement.Text = """"
.Execute Replace:=wdReplaceAll
' Now for the single quotes
.Text = ChrW(8216)
.Replacement.Text = "'"
.Execute Replace:=wdReplaceAll
.Text = ChrW(8217)
.Replacement.Text = "'"
.Execute Replace:=wdReplaceAll
' and finally the hyphen
.Text = ChrW(8211)
.Replacement.Text = "-"
.Execute Replace:=wdReplaceAll
End With
End SubThe ChrW() funtion returns the character identified by its unicode value.
8220 and 8221 are opening and closing double quotes. 8216 and 8217 are opening and closing single quotes and last but not least 8211 is the value for the en-dash character.
To read more about Unicode and why it’s important check out their website.