Failure to change ruby text's font via field codes

133 Views Asked by At

I run the below macro code that is capable of adding phonetic pinyin to all the selected Chinese text at once. However, that code can only add the ruby text using default settings for font and I need to modify the the font, positioning, and font size of the pinyin.

https://github.com/wuzhuoqing/alltextphonetic/blob/master/alltext.bas

At first, I tried to toggle the field codes to change the settings, and it worked. However, when I saved, exit, and re-opened it, only positioning and font size remained changed, the font was the same before I make changes via field codes.

For example, the original font of the ruby text is Times New Roman. I will change it into "DengXian" by toggling field codes. Then, the ruby text's font will be changed. However, once I save and reopen the document, the ruby text's font reverts back to "Times New Roman" instead of "DengXian".

Is there any solutions to it? Or, is it possible to make adjustments on the macro code so that it can abandon the ruby text's default settings and adopt my own? By the way, I am tired of using only Phonetic Guide because It would cost me much of time (The document contains more than 10000 words!)

Thank you!

2

There are 2 best solutions below

0
On

The short answer is that if you apply DengXian font to all the Ruby Text in the EQ fields, Word should get it right.

e.g. if your field looks like this after you have modified the \* "Font:Times New Roman" to \* "Font:DengXian"

{ EQ \* jc2 \* "Font:DengXian" \* hps11 \o\ad(\s\up 10(běn),本}

if you check the font of běn in the field code itself (not the field result) it will probably be Times New Roman. If you manually apply DengXian to běn, then save your document as .docx and re-open it, I think you will get the result you want.

You should be able to apply the correct font to all the ruby texts using an Advanced Find/Replace or maybe VBA if necessary, but longer term I think you need to try to ensure that Word is using the correct font in the first place, and that probably requires you to modify one or more Styles in the document. Right now, I can't tell you how to do that without further investigation of exactly which settings Word uses for that (by default, on my installation it uses DengXIan anyway for the ruby text).

As background...

When you modify the fontname in the \* "Font:fontname" switch in the EQ field, Word applies the font to the ruby text in the field result, but it does not apply the font to the ruby text in the field code. So in your case, that remains as Times New Roman.

If you save your document in the old .doc format, the field code is saved "as is". When you close and re-open, Word still has field, can still see the font you specified in \* "Font:fontname" and re-applies it to the field result.

But when you save in .docx format, Word does not actually save the field code at all. It translates it into WordProcessingML. At best, it records the font that has actually been applied to the ruby text in the field code. If you didn't actually apply any direct formatting to the ruby text, Word may decide that it has applied one of its Theme styles and record the font something like this (I am simplifying):

<w:rFonts w:asciiTheme="majorBidi">

At that point, it has forgotten that you specified \* "Font:DengXian". When you re-open the document, Word recreates the field, get the font from asciiTheme and generates `* "Font:Times New Roman" instead.

If you actually applied direct formatting to the ruby text, then Word seems to record the font name, more like this:

<w:rFonts w:ascii="DengXian">

Word has still forgotten that you specified \* "Font:DengXian", but gets the font name from the w:rFonts element and recreates \* "Font:DengXian"

0
On

Try to use the Document.Save method to make your changes permanent. The following example saves the active document if it has changed since it was last saved:

If ActiveDocument.Saved = False Then ActiveDocument.Save