1
votes

I looked at this link How to add phonetic guides to all the texts at once?, but it doesn't answer my question.

I'm using MS Word 2016 on a Mac. I read through what's written above but can't figure out how to do what I want.

I use the Phonetic Guide a lot and use it on just a few characters that I don't know. I would like to create a macro for it so I 1) don't have to highlight each character (not the biggest problem though), 2) don't have to click the phonetic guide icon (not the biggest problem though), 3) don't have to manually change the font (I like Arial Unicode MS), 4) don't have to manually change the Alignment to Centered.

I've tried to record a few macros but at first the macro only goes to the specific character that I created the macro with, it won't allow me to highlight another character the cursor just jumps back to the original character.

For example, in 我们特权, if I converted 我, then went to 们 and ran the macro, the cursor would jump back to 我.

I tried deleting the .Start = 2280 .End = 2281 from the macro which works on the specific character, but the macro records the "specific" Pinyin Ruby text from the original character, therefore when I run the macro on a "different" Chinese character, it places the same Pinyin Ruby text over the other character.

For example, I ran recorded the macro on 初 and got chū.

I then ran recorded the macro on 我 and also got chū.

Do you know enough about macros to make this work?

Thanks for any help you can give.

Scot PS, here are three macros I created.

Sub convert_to_Pinyin()
'
' convert_to_Pinyin Macro
'
'
    Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    With Selection
        .Start = 2280
        .End = 2281
        .Range.PhoneticGuide Text:="ch" & ChrW(363), Alignment:= _
            wdPhoneticGuideAlignmentCenter, Raise:=11, FontSize:=4, FontName:= _
            "Arial Unicode MS"
    End With
End Sub

Sub convert_to_Pinyin_R1()
'
' convert_to_Pinyin_R1 Macro
'
'
    With Selection
        .Start = 2372
        .End = 2373
        .Range.PhoneticGuide Text:="xí", Alignment:= _
            wdPhoneticGuideAlignmentCenter, Raise:=11, FontSize:=4, FontName:= _
            "Arial Unicode MS"
    End With
    With Selection
        .Start = 2371
        .End = 2372
        .Range.PhoneticGuide Text:="zuò", Alignment:= _
            wdPhoneticGuideAlignmentCenter, Raise:=11, FontSize:=4, FontName:= _
            "Arial Unicode MS"
    End With
    With Selection
        .Start = 2369
        .End = 2371
        .Range.PhoneticGuide Text:="tóng", Alignment:= _
            wdPhoneticGuideAlignmentCenter, Raise:=11, FontSize:=4, FontName:= _
            "Arial Unicode MS"
    End With
    With Selection
        .Start = 2369
        .End = 2369
        .Range.PhoneticGuide Text:="yì", Alignment:= _
            wdPhoneticGuideAlignmentCenter, Raise:=11, FontSize:=4, FontName:= _
            "Arial Unicode MS"
    End With
    With Selection
        .Start = 2368
        .End = 2369
        .Range.PhoneticGuide Text:="t" & ChrW(257), Alignment:= _
            wdPhoneticGuideAlignmentCenter, Raise:=11, FontSize:=4, FontName:= _
            "Arial Unicode MS"
    End With
    With Selection
        .Start = 2367
        .End = 2368
        .Range.PhoneticGuide Text:="y" & ChrW(468), Alignment:= _
            wdPhoneticGuideAlignmentCenter, Raise:=11, FontSize:=4, FontName:= _
            "Arial Unicode MS"
    End With
    With Selection
        .Start = 2366
        .End = 2367
        .Range.PhoneticGuide Text:="néng", Alignment:= _
            wdPhoneticGuideAlignmentCenter, Raise:=11, FontSize:=4, FontName:= _
            "Arial Unicode MS"
    End With
    With Selection
        .Start = 2364
        .End = 2366
        .Range.PhoneticGuide Text:="quán", Alignment:= _
            wdPhoneticGuideAlignmentCenter, Raise:=11, FontSize:=4, FontName:= _
            "Arial Unicode MS"
    End With
    With Selection
        .Start = 2364
        .End = 2364
        .Range.PhoneticGuide Text:="tè", Alignment:= _
            wdPhoneticGuideAlignmentCenter, Raise:=11, FontSize:=4, FontName:= _
            "Arial Unicode MS"
    End With
    With Selection
        .Start = 2362
        .End = 2364
        .Range.PhoneticGuide Text:="men", Alignment:= _
            wdPhoneticGuideAlignmentCenter, Raise:=11, FontSize:=4, FontName:= _
            "Arial Unicode MS"
    End With
    With Selection
        .Start = 2362
        .End = 2362
        .Range.PhoneticGuide Text:="w" & ChrW(466), Alignment:= _
            wdPhoneticGuideAlignmentCenter, Raise:=11, FontSize:=4, FontName:= _
            "Arial Unicode MS"
    End With
    With Selection
        .Start = 2361
        .End = 2362
        .Range.PhoneticGuide Text:="g" & ChrW(283) & "i", Alignment:= _
            wdPhoneticGuideAlignmentCenter, Raise:=11, FontSize:=4, FontName:= _
            "Arial Unicode MS"
    End With
    With Selection
        .Start = 2360
        .End = 2361
        .Range.PhoneticGuide Text:="cì", Alignment:= _
            wdPhoneticGuideAlignmentCenter, Raise:=11, FontSize:=4, FontName:= _
            "Arial Unicode MS"
    End With
    With Selection
        .Start = 2359
        .End = 2360
        .Range.PhoneticGuide Text:="shén", Alignment:= _
            wdPhoneticGuideAlignmentCenter, Raise:=11, FontSize:=4, FontName:= _
            "Arial Unicode MS"
    End With
End Sub

Sub convert_to_Pinyin_R2()
'
' convert_to_Pinyin Macro
'
'
    Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    With Selection
        .Range.PhoneticGuide Text:="ch" & ChrW(363), Alignment:= _
            wdPhoneticGuideAlignmentCenter, Raise:=11, FontSize:=4, FontName:= _
            "Arial Unicode MS"
    End With
End Sub
1
Sorry, I'm just a Word user who uses the MS Word macro recording function. I don't even know what a "code block" is.Wilkins
Sorry for using jargon. I was just referring to the grey highlighting you can put over code in your post to format it and keep it organized from text. It looks like someone edited your post to add them. It just makes it easier to read. Good luck! I hope you find a solution to your problem.divibisan

1 Answers

0
votes

Your macros are a good start. The trick is to move the focal point.

The following starts out with your selection - in my test I copied and pasted what you show us and selected those four characters.

The selection is assigned to a Range, which you can think about as a Selection but there can be many of them in your code (while there can be but one Selection) and the user doesn't see them. This means the screen also doesn't "jump" when the focus changes.

Since the code should move automatically through the characters ("loop") it next gets the total character count, then sets up a loop. Note that the loop works backwards. This is because Word EQ fields are substituted for the characters, which is the same as destroying the original and putting in a new one. So it only works backwards.

An InputBox then requests the phonetic text from you. And finally, the code you recorded is executed, using your input.

Sub PhoneticGuide()
    Dim r As word.Range, c As word.Range
    Dim s As String, i As Long
    Dim lCountChars As Long

    Set r = Selection.Range
    lCountChars = r.Characters.Count

    For i = lCountChars To 1 Step -1 'In r.Characters
      Set c = r.Characters(i)
      s = InputBox("Enter the phonetic equivalent")
      c.PhoneticGuide Text:=s, Alignment:= _
            wdPhoneticGuideAlignmentCenter, Raise:=11, FontSize:=4, FontName:= _
            "Arial Unicode MS"
    Next
End Sub