Pinyin Zhou logo Pinyin Joe's
Chinese Computing Help Desk

Click. Work. Collect.

Pinyin Macros for MS Word and Excel

Automatically convert pinyin with tone numbers
into pinyin with tone marks (diacritics)

Hanyu Pinyin tones

Download Macro for Word: Windows Office 97 or later, Mac Office 98 - 2004
(Version 1.1, released Sept. 2005. Size: 1 KB Zip file, 10 KB text file.)

Download Macro for Excel: Windows Office 97 or later, Mac Office 98 - 2004
(Version 1.1, released June 2008. Size: 2 KB Zip file, 19 KB text file.)

Not Compatible with Macintosh Office 2008 or iWorks Pages.
(Conversion of the above VBA macros into AppleScript is planned for the near future.)

 

See also my third-party add-ins page for pinyin solutions from others, including Pinyinput, a free Pinyin with tone marks IME for Windows.

Having trouble with Word's Phonetic Guide for placing pinyin "ruby text" above your Chinese characters? See the Phonetic Guide FAQs for help.

 

Pinyin Macro Instructions
Overview ... Use These Fonts... Installation... Ruby Text 


Pinyin Macro Help
FAQs & Technical Notes ... Contact Information


Overview

These macros are very simple to use, as easy as "1-2-3":

  1. Type pinyin with numbers representing the tones. For example, "Han4yu3 Pin1yin1".
  2. Select the text in Word or cells in Excel. Or, you can convert entire documents: in Word, leave the cursor at the end of any block of text you want to convert. In Excel, the next step will offer you a choice of selected cells, entire worksheets or all worksheets in a workbook.
  3. Invoke the macro by pressing <alt-F8> and double-clicking on the macro name.*

Simple as that!

*In Excel, you can assign a keyboard shorcut to each macro by clicking the Options button you will see there. In Word, you may want to raise this macro to the top of the list by adding "aa" to the front of the name so you can just hit <Enter> instead of double-clicking on the macro name.


Use These Fonts

To use this macro, the only other thing to remember is that you'll need to select one of the following fonts:

Arial
Courier New
Times New Roman

Arial, Courier New, Times New Roman In most recent versions of Office, these "core" fonts have been updated to include at least enough of the Unicode character set to display pinyin with tone marks.
Arial Unicode MS Arial Unicode The default Unicode font, included since MS Office 2000. Safest for use in Access databases too.
Lucida Sans Unicode Lucida Sans Unicode The default Unicode font in earlier versions of Windows. Also used in Mac systems.

Windows Vista and Office 2007 include all of these fonts. Just avoid using Office 2007's default font, Calibri, which does not include all the characters you need. You may not notice at first, but if you use Calibri some but not all of the letters will convert to Arial and the final result will be ugly.

Office XP (2002) and 2003 include the latest Arial, Courier New and Times New Roman, and those editions also normally install the Arial Unicode MS font as the "Universal Font", also known as the "Unicode Font" as part of International Support.

In Office 2000 that font is an option. If you did not install it, for either XP 2002/2003 or 2000, follow the instructions for "Installing the Unicode Font" on Microsoft's "Administering Fonts for Office XP" page.

I'm not sure how to find that font if you're missing it in older versions of Macintosh Office, but I bet Mac users don't even have this kind of problem.

Again, you do not need to worry about missing any of these fonts in Windows Vista or Office 2007, or for most installations of Office XP/2002/2003, so just go ahead and try using the macro first before getting concerned with this.

«Top

Installation

Click one of the download links at the top of this page, and copy/extract the file to your PC.

To install, open Word or Excel as appropriate and press <alt-F8> (or on the Mac <Cmd-F8> right? It's been awhile...). Type a name for the macro and hit the "Create" button. Then open the downloaded file, select all the text and copy it into a blank macro. Paste it between the lines already in there, "Sub" and "End Sub", being careful not to erase those!

The Excel macro must have a very specific name, noted on one of the first comment lines in the file. You can call it anything when you first create the blank macro, but then follow the instructions in the comment lines for renaming. If you don't do this, the macro will convert text in selected cells but the versions for worksheets and entire workbooks will not run. Also, if your Excel is set to insert the command "Option Explicit" into a new macro module, make sure you end up with only one instance of that in each module.

If you need further help creating or saving a macro, the Help files in Word and Excel have all the information you need. Just enter "macro" in the Help index and drill down to info on creating a macro "from scratch". Excel can be especially difficult about security: you must enable macros, and in some versions of Excel you must save your final spreadsheet as a macro-enabled file. See also the Troubleshooting section of the pinyin macro FAQ page.

If you get ambitious, the Help files in Visual Basic editor (launched when you click the "Edit" button in the macro dialog within Word or Excel) can help you add tweaks of your own. For example, you can tell the Word macro to search forward from your cursor instead of backwards by setting "Forward=" to "True".

«Top

Ruby Text

Although you can use this macro to create "ruby" text (small phonetic transcriptions aligned above or alongside Chinese characters), there is an easier way: there are inexpensive Chinese character fonts available that include pinyin ruby text. MS Word's Phonetic Guide can help you do the same thing without buying a font, but I hate that feature...it really is not a finished product. With either of these options you'll have to input the Chinese characters first of course. See this section of my zhuyin setup page for more information: zhuyin and pinyin ruby fonts and Word's Phonetic Guide.

«Top

Need More Help?

There is a Troubleshooting section on the macro FAQ page. I've tested these macros in the Windows versions of Office 2007 (use one of the fonts listed above, not the default Calibri), Office 2003, Office XP 2002 and Office 97. I am told they also work in Macintosh Office 98 through 2004, and maybe even the mid-nineties version 4.2, but Mac Office 2008 is not compatible with this type of macro. I hope to get these VBA macros converted to AppleScript soon. Please send questions, comments or suggestions anytime via the contact page.

«Top
 

Windows 7: First Look Free Downloads Third-Party Fonts and Apps    Frequently Asked Questions Home...About...Contact
Vista Chinese Setup Vista Pinyin Setup Vista Zhuyin Setup    Vista Chinese Fonts Vista Language Packs (MUI)
XP East Asian Setup XP Pinyin Setup XP Zhuyin Setup    XP Chinese Fonts XP Chinese User Interface (MUI)

Copyright © 2005 PinyinJoe.com.  All Rights Reserved.
"Microsoft", "Windows", "Vista" and any other trademarks on this site are the sole property of their respective owners.