Welcome / Bienvenue / Benvinguts / Bienvenidos
For information about my translation services, please visit the main site.
Pour des informations sur mes services, merci de regarder le site principal.
Para información sobre mis servicios de traducción, visite el web principal.

Macro to replace smart quotes and smart apostrophes with straight quotes and straight apostrophes in Word

UPDATE: I no longer recommend this macro because it does not look at footnotes and text boxes. Instead, you should use the macro available here.

Many users of CAT tools like to convert smart quotes and apostrophes to straight ones before translating their documents, because if the straight versions are always used, it means concordance searches for words including apostrophes will always work.

The problem is that it takes quite a while to do this in MS Word. You can’t just find/replace the apostrophes, because even if you put a straight apostrophe in the replace box, Word will interpret it as a smart apostrophe if you have set Word up to use straight apostrophes and quotes.

Of course, you could change that setting, but then it is more complicated to convert the straight varieties to the smart varieties after exporting from your CAT tool.

The solution is to use a macro that will automatically switch smart quotes and apostrophes off, then perform the search, then switch them back on.

Here’s a macro that will do just that.

Option Explicit
Sub ReplaceQuotes()
' ReplaceQuotes Macro, by Timothy Barton, Anglo Premier Translations
'
Application.Options.AutoFormatAsYouTypeReplaceQuotes = False
Selection.find.ClearFormatting
Selection.find.Replacement.ClearFormatting

With Selection.find
.Text = ChrW(8220)
.Replacement.Text = """"

.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False

End With
Selection.find.Execute Replace:=wdReplaceAll

Selection.find.ClearFormatting
Selection.find.Replacement.ClearFormatting
With Selection.find
.Text = ChrW(8221)
.Replacement.Text = """"

End With
Selection.find.Execute Replace:=wdReplaceAll

Selection.find.ClearFormatting
Selection.find.Replacement.ClearFormatting
With Selection.find
.Text = "´"
.Replacement.Text = "'"

.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False

End With
Selection.find.Execute Replace:=wdReplaceAll

Selection.find.ClearFormatting
Selection.find.Replacement.ClearFormatting
With Selection.find
.Text = "‘"
.Replacement.Text = "'"

.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False

End With
Selection.find.Execute Replace:=wdReplaceAll

Selection.find.ClearFormatting
Selection.find.Replacement.ClearFormatting
With Selection.find
.Text = "’"
.Replacement.Text = "'"

.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.find.Execute Replace:=wdReplaceAll
Application.Options.AutoFormatAsYouTypeReplaceQuotes = True

Dim oShell As Object
Dim iResponse As Integer
Set oShell = CreateObject("Wscript.Shell")

iResponse = MsgBox("Procedure complete. Code provided by Timothy Barton, Anglo Premier Translations. Would you like to visit the website?", _
vbYesNo, "Procedure complete")

If iResponse = vbYes Then
oShell.Run ("http://www.anglopremier.com?utm_campaign=apostrophesmacro&utm_medium=referral&utm_source=blog")
Else
Exit Sub
End If

End Sub

Share:

Leave a Reply

Your email address will not be published. Required fields are marked *