Because I am not familiar with the Word macro commands, I break the task into three parts, first, understand the cursor movement instructions, second, understand the pinyin command; third, make some landscaping adjustments to the typesetting.
1th, not complicated, simply record a macro, move the cursor, it is very clear to see the moving instructions.
Selection.moverightunit:=wdcharacter,count:=1,extend:=wdextend
Next, I took a quick look at the Selection object and some of the move prefixes in MSDN to get a sense of some of the moving instructions.
2nd, I right click on the menu, in the custom menu to find the "phonetic standard" corresponding to the command formatphoneticguide, to search for the keyword, quickly get the macro used in the simple call method, but this method I feel unscientific, if the software processing response time to keep up, It's easy to crash, but there's no better way:
SendKeys "{Enter}", 2 ' analog keyboard input, 2 is the waiting time, because the phonetic annotation of the dialog box called in the back, in order to correctly send the return key message to it, to wait a few seconds, in fact, the greater the security, but the waiting time is too long will affect the operation of the program efficiency, this method I think not very , but did not find the other information of Formatphoneticguide, also will use this stupid method! application.runmacroname:= "Formatphoneticguide"
3rd, in order to make the text easier to read after pinyin, I decided to add a space between each word, otherwise, the pinyin is all squeezed together, will make the child in spelling confused, this is quite simple, recording a macro, click the keyboard arrow right move, and then play a space, in the program can be this action cycle.
Addpinyin of the macro soon to write well, I have a single step, nothing unexpected, the effect is not bad, directly on the result map. Like friends can also see the full macro code.
The code is as follows : copying content |
Sub Addpinyin () ' Author:missilecat date:20140410 version:1.0.0 ' Addpinyin macros ' For a complete word text with the Mark </p> <p> Dim Tinttreatingcount as Integer Dim Tstrchara as String Dim Tlngcurpos as Long Dim Tinta as Integer</p> <p> Selection.wholestory Tstrtext = Selection.Text Tinttextlength = Selection.Characters.Count Tintlinestart = 1</p> <p> tinttreatingcount = 0</p> <p> Selection.goto what:=wdgotoheading, Which:=wdgotoabsolute, count:=1</p> <p> selection.moveright unit:=wdcharacter, Count:=1, Extend:= Wdextend Selection.goto what:=wdgotoheading, Which:=wdgotoabsolute, count:=1 For tintloopx = 1 to Tinttextlength Tlngcurpos = Selection.MoveRight (Unit:=wdcharacter, Count:=1, Extend:=wdextend) Tstrchara = Right (Selection.Text, 1) If AscW (Tstrchara) < 255 and ASCW (Tstrchara) > -255 Then If tinttreatingcount > 0 Then Tinta = Len (Selection.Text) SendKeys "{Enter}", 2 Application.Run macroname:= "Formatphoneticguide" Selection.MoveRight Unit:=wdcharacter, count:=tinta</p> <p> tinttreatingcount = 0</p> <p> End If Else Tinttreatingcount = Tinttreatingcount + 1 End If next</p> <p> ' Add spaces for each word Selection.goto what:=wdgotoheading, Which:=wdgotoabsolute, count:=1</p> <p> ' Selection.homekey unit:= Wdstory</p> <p> for tintloopx = 1 to Tinttextlength Selection.MoveRight Unit:=wdcharacter, Count:=1 Selection.TypeText text:= "" Next MsgBox "Task completed successfully" ' . Range.phoneticguide text:= "Lǐ", alignment:= _ ' Wdphoneticguidealignmentonetwoone, raise:=15, fontsize:=8, FontName _ ': = "song Body" End Sub |