Pinyin Zhou logo Pinyin Joe's

Chinese Computing Help Desk

 


Custom Search

Pinyin Macros

Automatically convert Pinyin with tone numbers
to Pinyin with tone marks (diacritics)

Hanyu Pinyin tones

Downloads

Microsoft Office
Windows or Mac*
LibreOffice or OpenOffice
Windows, Mac, or Linux
Word — whole documents
(Supports tables.)
Writer — whole documents
 
Word — selected text
(Selected text or text before cursor.)
Writer — selected text
(Selected text only.)
Excel — selected cells
Calc — selected cells
PowerPoint
Impress - not yet available
(Want to help?)

*Not Compatible with Office for Mac 2008 or Apple iWork. See FAQ for more info.

 

Pinyin Macro Instructions
Overview ... Use The Right Font... 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, as in "Han4yu3 Pin1yin1".
  2. Select the text or document you want to convert.
  3. Run the macro. Done.

To run macros, in Word or Excel for Windows press <alt-F8> or add the macro to your Quick Access Toolbar. In Office for Mac, go to Tools > Macros. In Libre/OpenOffice, go to Tools > Macros > Run Macro...

Use The Right Font

To use this macro, the only other thing to remember is that you'll need to select a font that includes letters with these diacritics. Otherwise you may find that in each word the one letter with a tone will be in a different font.

In Ubuntu Linux, I've found the default Liberation Serif and the other "Liberation" fonts do not have everything we need, but Free Sans, DejaVu Sans, DejaVu Serif, "Ubuntu" and many others look great. Starting with 16.04 / Xerus, Ubuntu includes the Google Chinese font Noto Sans CJK (also available for other systems as a free download under that name or as Adobe Source Han Sans), and that font also includes all the letters with diacritics we require for Hanyu Pinyin tones.

Macs have had Unicode fonts for years. Not every font on a Mac will have these letters, but worrying about Unicode fonts is mostly a Windows thing these days, and Microsoft is getting better and better about that too.

In Windows, use one of these:

Latin fonts

Arial
Courier New
Times New Roman

Calibri*
Cambria*

Arial, Courier New, Times New Roman

In 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. (See my note below about the default Calibri and Cambria fonts in Office 2007. Office 2010 and later are OK).

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.
Chinese fonts
Microsoft YaHei Lucida Sans Unicode Included with Windows 8 and later.
Adobe Source Han Sans (Google Noto Sans CJK) Lucida Sans Unicode Free open-source Pan-CJK font.

*Windows Office 2010 and later versions include all of these fonts, but Calibri and Cambria did not include all the necessary characters in Office 2007 until I installed Office Multi-Language Pack 2007. new site

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.

Installation

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

To install in Microsoft Office, open Word or Excel and in Windows press <alt-F8>, or on a Mac go to Tools > Macros. 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. Note my instructions in each macro on exactly where and how to paste it, especially the part about the "sub" and "end sub" lines. 99 times out of 100, the reason a macro doesn't work will be a mistake pasting it in during this step.

The MS Office Help files on this topic are actually are pretty good. Open Help, enter "macro" in the Help index, and drill down to info on creating a macro "from scratch". (Note that Excel can be especially difficult about security: you must enable macros, and in recent versions of Excel you must save your final spreadsheet as a macro-enabled file.)

To install in OpenOffice or LibreOffice, go to Tools > Macros > Organize Macros > LibreOffice (or OpenOffice) Basic to create a macro and paste in my code. Here's a link to someone offering more detailed help: 5 Steps to Creating an OpenOffice Macro. arrow - new site In his step 5, instead of writing a macro you would paste in one of mine, making sure to follow my instructions in the macro comments about deleting the "sub Main" and "end sub" lines automatically created for any new blank macro.

When running these macros in OOo or LibrO, if you get a message saying you need a "Java runtime environment" (JRE), that has nothing to do with me and you can run macros without it, but I know how to make that annoyance go away in Linux: install OpenJDK Java Runtime. This is easy in Ubuntu. Open Software Center, search for LibreOffice, click the "More Info" button, scroll down to find OpenJDK Java Runtime, select it and click the "Apply changes" button above.

The Help files on this topic included with Open/LibreOffice are not very detailed, but there is some information there. Look under "Macros" (plural) and click through "Organize Macros" to "LibreOffice Basic".

See also the Troubleshooting section of the Pinyin macro FAQ page. If you get ambitious, the Help files in the Basic editors (launched when you click the "Edit" button in the macro dialog) can help you add tweaks of your own. For example, you can tell the MS Word macro to search forward from your cursor instead of backwards by setting ".Forward=" to "True", or you can remove that feature entirely.

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, and there are the Phonetic Guide features of Word and Writer. With any 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 on Zhuyin and Pinyin ruby fonts, and Microsoft Word's Phonetic Guide, and this a brief discussion of Phonetic Guide in LibreOffice/OpenOffice (in my Ubuntu Linux section, but there is also a version of OpenOffice for Windows), which someone is trying to automate by developing an an extension called OOPinyinGuide.

Need More Help?

Please see the Troubleshooting section on the macro FAQ page, and feel free to send send questions, comments or suggestions anytime via the contact page.

« top




Home / What's New About Pinyin Joe About Pinyin About Pinyin Input Contact Pinyin Joe
Windows 10 & 8 Chinese Windows 7 & Vista Chinese Windows XP Chinese Ubuntu Linux Chinese Other OS: Android, Mac, ...
More Chinese Fonts More IMEs & tools Free Downloads FAQs Site Map

Copyright © 2005 PinyinJoe.com.  All Rights Reserved.   Page copy protected against web site content infringement by Copyscape
"Microsoft", "Windows", "Linux", "Ubuntu", "Apple", "Macintosh" and any other trademarks on this site are the sole property of their respective owners.