VBA Microsoft Word Phonetic Guide For Chinese Pin Yin, Control Dialog Box
Reference: "Alex C" video "VBA Excel Macro Stops Working When a Dialog Box Pop Up Appears - InternetExplorer.Application" from Youtube and reply by "Karen White".
Merry Christmas 2017 to all readers, appended below is a VBA code to add Microsoft Word's default Chinese Pinyin as Phonetic Guide or Ruby Text to Chinese Characters.
Quote
Sub Chinese_PhoneticGuide()
Dim c As Integer Dim wsShell As Object
Set wsShell = CreateObject("WScript.Shell") '(Set VBScript)
For c = 1 To 10 '(Range of characters to add Phonetic Guide) If ActiveDocument.Range.Characters(c) = Chr(13) Then GoTo Line1 '(Check if c is a carriage return) ActiveDocument.Range.Characters(c).Select '(Selects 1 character) wsShell.AppActivate ("Phonetic Guide") '(Add before the dialog popup fires) wsShell.SendKeys "%l" '(Select Alignment) wsShell.SendKeys "c" '(Select Alignment Centered) wsShell.SendKeys "~" '(Confirm Alignment Centered) wsShell.SendKeys "~" '(Close PhoneticGuide Dialog)
Dialogs(wdDialogPhoneticGuide).Execute Line1: Next c
End Sub
Unquote
As many of you who have tried adding Chinese Pinyin as Phonetic Guides would know that manually, you could only successfully add 5 to 20 characters before the rest return blank.
Using VBA Properties and Methods to add Phonetic Guides would also not provide the default Pinyin from Word, therefore the Dialog Box is used in the above code to generate the default Pinyin or Ruby Text.
Confirming and closing the Dialog box after it pops up was easier Clicked than Coded but thanks to Alex C's video and Karen White's commented reply on youtube, the VBA code could continue to run after the dialog box was executed.
Cheers to our English readers on your Chinese learning journey.
If you have a better way of adding Pinyin to Chinese Characters, please share with us in the comments below.