How to use Unicode in Word X on the Macintosh

Article contributed by John McGhie

This article provides help for people who need to use Unicode in Word X on the Macintosh.  This article requires some technical skills. This is as good a time as any to get started learning some fancy, advanced techniques with Word X.

This proposed solution is far from ideal, so let's set some expectations up front:

This solution enables "some" users to use "some" characters to get by for now.  If it doesn't suit you, it's time to upgrade to Word 2004.

The Ground Rules

This solution relies on several facts:

My solution consists of three macros.  One enables you to enter any Unicode character you like into a Word document by typing its hexadecimal code into the text.  Another enables you to select any character and return its Unicode value.  The last one enables you to list all of the characters defined in each of your fonts so that you can see what those codes are. 

Click here for a template containing the compiled macros.

Look here for instructions on installing a template.

Look here for instructions on installing macros.

If you use this solution, you will be left with a document containing characters you cannot see.  Current Carbon applications will not display any character that is not in the Macintosh Character Set.  Word displays the characters as an underscore.

Viewing Documents containing Unicode

To view the document, you will have to save it as a Web Page and open it in Internet Explorer.  Since this shatters your document's layout, it is useful only for confirming that you have the correct character in the correct place.

Printing Documents containing Unicode

To print the document, you will have to Save As RTF then print it from TextEdit.  As far as I know, you cannot get Unicode characters into PDF yet, because the PDF writer is a Carbon application.  Of course, if you email the document to work, you can print it from your PC....

Entering Unicode Characters

The first problem is how to enter characters.  The Unicode Hexadecimal keyboard required to type special characters is not available in Word (it will enable only in genuine Unicode applications). 

Making Word Show You the Whole Font

This is nasty but it works:

  1. Type a whole word including the following space.  It must not be a spelling error.
  2. Double-click to select the word.
  3. Do not move your insertion point.
  4. Format the word with the font you are interested in.
  5. If you have done it right, the Insert>Symbol dialog in Word will now show the name of the font instead of Normal Text.  If the name of the font does not appear, try again; this won't work until you get the name of the font to stick.  Hint: Do not click in the word after you have selected it; if you do, Word cancels the font formatting.  It's a bug.
  6. If the font is a Unicode font, all characters will now appear in Insert>Symbol.
  7. If the font has multiple subsets, the Unicode scrollbars will appear.
  8. You can insert the character using Insert>Symbol.  It will replace the highlighted word.

Return to Top

Macro to Insert Unicode Characters

Here is a macro that will insert any Unicode character you like in a Word v.X document:  To use it, you type the four-character number in the document and run the Macro.

Click here for a template containing the compiled macros.

Look here for instructions for installing a template.

Look here for instructions on installing macros.

Macro Code

Sub InsertUnicode()

' InsertUnicode Macro

' Macro written 26 Jul 2002  by John McGhie

' Converts typed text into Unicode

Dim CharNum As Long

Selection.Collapse

Selection.MoveStart Unit:=wdWord, Count:=-1

If Selection.Text <> "" Then

    CharNum = Val("&H" & Selection.Text)

    If CharNum < 0 Or CharNum > 65535 Then

        MsgBox "Sorry, there is no such character in Unicode. " _

        & "The character code must be four digits in hexadecimal."

    Else

        Selection.TypeText Text:=ChrW(CharNum)

    End If

End If

End Sub

When we send Macros over the Internet, various things can happen to the lines and cause errors.  To see if you got any, go to Debug and choose Compile Normal.

If a warning dialog pops up telling you about a "Compile Error" this usually means that one of the lines has wrapped on its way to you.  The line after the error will turn red.  Usually all you have to do is use the Delete key to join that line onto the end of the one above.

When you have no errors, click Save, then click the blue W button to come back to the Word user interface.  Assign this macro to a keystroke:  Word 2002 for Windows has this command built-in; the default keystroke for it is Alt + x.  Since the Mac won't let you use Option (it's reserved for the operating system) and Alt is a bit of a stretch, try Ctrl + x; that's available.

Look here for How to Assign a Macro to a Keystroke

Hold down your Shift key and choose File>Save All.  Save All does not appear unless you do hold down the shift key.  You wouldn't want to lose all this work in a crash. Now would you?

How to Insert a Unicode Character

To use the macro, simply type the hexadecimal character code into the document where you want the character to appear, then hit the keystroke you assigned. 

The macro will convert the character code to a Unicode character.

The reason this macro is provided in hexadecimal is because most of the font utilities around provide the character codes for characters in hex.  If yours works in Decimal, go back to the Macro editor, open the code window and change the line that reads

CharNum = Val("&H" & Selection.text)

to read just

CharNum = Val(Selection.text)

That removes the conversion from Hexadecimal.  To be elegant, you may want to remove the words "in hexadecimal" from the end of the MsgBox line.

How to find the Unicode Value of a Character

Run the following Macro.

Click here for a template containing the compiled macros.

Look here for instructions for installing a template.

Look here for instructions on installing macros.

Macro Code

Sub ShowCharacterCode()

'

' Charcode Macro

' Macro recorded 8/06/00 by John McGhie

'

MsgBox AscW(Selection.Text)

 

End Sub

Return to Top

How to Find Unicode Characters in your Fonts

The following macro enables you to list all of the characters in a font.  The reason you have to do this is because most Macintosh fonts contain characters that Word cannot display.

Apple and Microsoft fonts supplied with OS X and Office v.X are actually Unicode fonts.  However, in common with most other Carbon applications, Word can display only the characters in the Macintosh Character Set.  Most fonts contain many more characters you cannot see, but you can use them if you can get their character numbers.

Windows fonts typically contain five times more characters than Macintosh fonts.

Macintosh OS X can use Windows fonts of kind OTF (OpenType Font) and TTF (TrueType Font).  PostScript (Type 1) fonts made for Windows will not work on the Mac.  Simply drag compatible fonts to your Fonts folder.  It doesn't matter which of your fonts folders you use; you may wish to use the Fonts folder you will find in your Microsoft Office X/Office Folder to avoid the possibility of interfering with other applications.

The following macro produces a listing of the font you choose.  It places all 65,536 character codes possible in Unicode into a document, 16 to a line.  When you display or print the result,  the character will appear at each position for which the selected font has a character defined.  You will get a question mark or a hollow box where there is no character in the font.

Notes:

List Unicode Font Macro Code

Click here for a template containing the compiled macros.

Look here for instructions for installing a template.

Look here for instructions on Installing a Macro.

Macro Code

Sub ListUnicodeFont()

 

' Macro written 28 July 2002 by John McGhie

' Prints entire character set of a unicode font

 

Dim theFont As String

Dim fontDoc As Document

Dim tabNumber As Integer

Dim charNumber As Long

 

charNumber = MsgBox("Choose just the font name from the following Dialog" _

        & " box, then wait...", vbOKCancel + vbInformation)

If charNumber <> 1 Then End

 

With Dialogs(wdDialogFormatFont)

    .Display

    theFont = .Font

End With

 

Set fontDoc = Application.Documents.Add

fontDoc.Activate

fontDoc.ActiveWindow.View.Type = wdNormalView

 

StatusBar = "Please wait..."

 

Selection.TypeText "Character listing for " & theFont

Selection.Paragraphs(1).Format.Style = wdStyleHeading1

Selection.TypeParagraph

 

Selection.TypeParagraph

With Selection.Paragraphs(1).TabStops

    For tabNumber = 3 To 17

        .Add Position:=(tabNumber * 22), Alignment:=wdAlignTabRight

    Next tabNumber

End With

   

Selection.Font.Name = "Arial"

Selection.TypeText "Number"

For tabNumber = 0 To 15

    Selection.TypeText Text:=vbTab & Hex(tabNumber)

Next tabNumber

 

x = 32

While x < 65532

    Selection.TypeParagraph

    Selection.Font.Name = "Arial"

    Selection.TypeText Text:=Hex(x)

    StatusBar = "Character number " & Hex(x)

    For tabNumber = 1 To 16

        Selection.Font.Name = theFont

        Selection.TypeText Text:=vbTab & ChrW(x)

        x = x + 1

    Next tabNumber

Wend

 

' The PC substitutes the closest available font if

' the character is not available in the nominated font.

' The following routine marks characters Blue if they

' are from the requested font, and dark red if they

' have been substituted. This routine is not necessary

' on the Mac, which doesn't have the function

#If Win32 Then

    Selection.Find.ClearFormatting

    Selection.Find.Replacement.ClearFormatting

    With Selection.Find

        .Text = ""

        .Font.Name = theFont

        .Replacement.Text = ""

        .Replacement.Font.Color = wdColorBlue

        .Forward = True

        .Wrap = wdFindContinue

        .Format = True

        .MatchCase = False

        .MatchWholeWord = False

        .MatchWildcards = False

        .MatchSoundsLike = False

        .MatchAllWordForms = False

    End With

    Selection.Find.Execute Replace:=wdReplaceAll

 

    Selection.HomeKey Unit:=wdStory

 

    Selection.Find.ClearFormatting

    Selection.Find.Replacement.ClearFormatting

    With Selection.Find

        .Font.Color = wdColorAutomatic

        .Replacement.Font.Color = wdColorDarkRed

    End With

    Selection.Find.Execute Replace:=wdReplaceAll

#End If

 

fontDoc.SaveAs FileName:=theFont & ".doc"

fontDoc.WebOptions.Encoding = msoEncodingUTF8

 

' The Mac has different HTML Options in the Save As

#If Mac Then

    fontDoc.SaveAs FileName:=theFont & ".htm", _

    FileFormat:=wdFormatHTML, _

    HTMLDisplayOnlyOutput:=True

#Else

    fontDoc.SaveAs Encoding:=msoEncodingUTF8, FileFormat:= _

    wdFormatFilteredHTM

#End If

 

ActiveWindow.View.Type = wdWebView

 

End Sub

Return to Top