Automagical font macro

by on June 16, 2015

One of the frustrations of working in biblical studies is juggling fonts. It is not uncommon to be working with three languages at once, and often different fonts are required. Some word processors will automatically switch fonts when you switch input keyboards. Word for Windows can do this in the complex script settings. But I haven’t found one that will do this easily for three languages at a time. That’s too bad, because I’m often using Greek and Hebrew (and English) all in one document.

One solution is to pick one font that has sufficient Unicode ranges and use it all the way through. Cardo is a decent possibility here if you hate Times New Roman. Often, though, specific fonts are required, e.g. SBL BibLit. And I think I’ve found a better way. Times New Roman has sufficient range, so I can compose everything without bothering to change fonts. And when I’m done (or whenever I feel like it), I can run a macro to change all of the Greek and Hebrew for me.

This blog post from Mark Ward gave me the breakthrough I needed. One snag I hit was finding out there are two Unicode ranges I need to cover for each language: Greek also has a “Greek Extended” range, and Hebrew characters with a dagesh show up later in an “Alphabetic Presentation Forms” range.

Now that it’s all sorted, I can hit the keyboard shortcut I assigned and watch as Word changes all of my Greek and Hebrew for me. I did find out, incidentally, that the macro doesn’t like Track Changes to be on. Still haven’t worked out why. I’ll paste the Visual Basic code below for those who want to give it a try.

(WordPress isn’t preserving the formatting for some reason, so here is a plain text file.)

Sub Fonts()
'
' Fonts Macro
' This Macro changes all Hebrew and Greek Unicode characters in a document to a specified font.
' The font name can be changed; in this case the font specified is SBL BibLit.

Selection.WholeStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.WholeStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "[" & ChrW(880) & "-" & ChrW(1023) & "]"
' This is the basic Greek Unicode range.
.Replacement.Font.Name = "SBL BibLit"
.Forward = True
.Wrap = wdFindAsk
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "[" & ChrW(7936) & "-" & ChrW(8190) & "]"
' This is the extended Greek Unicode range.
' This range will catch Greek characters with combining diacritics
' such as accents and breathing marks.
.Replacement.Font.Name = "SBL BibLit"
.Forward = True
.Wrap = wdFindAsk
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "[" & ChrW(1425) & "-" & ChrW(1524) & "]"
' This is the basic Hebrew Unicode range.
.Replacement.Font.Name = "SBL BibLit"
.Forward = True
.Wrap = wdFindAsk
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "[" & ChrW(64285) & "-" & ChrW(64335) & "]"
' This includes the Hebrew alphabetic presentation forms.
' This range will catch Hebrew characters with a dagesh.
.Replacement.Font.Name = "SBL BibLit"
.Forward = True
.Wrap = wdFindAsk
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Execute
End Sub

If you prefer to set this up by recording a macro rather than pasting in a block of VB code, you can follow these steps. You will, however, still have to go into the VB editor to change the code.

  1. Click on Record on the Developer Tab to begin recording a macro.
  2. Run four sets of find/replace all.
    1. For the first, paste [Ͱ-Ͽ] into Find, check Use Wildcards, click in the Replace box and then click on Format, changing Font to desired font (e.g., SBL BibLit). Then Replace All!
    2. Repeat with [ἀ-῾]. These are the two Greek Unicode ranges.
    3. Repeat with [֑-״].
    4. Repeat with [יִ-ﭏ].
  3. Now open the Visual Basic editor.Visual Basic thinks you are trying to replace the Unicode characters with nothing, so the line that has .Replacement.Text = “” needs to be replaced with
    .Replacement.Font.Name = “SBL BibLit”
  4. Now it should work!