问题描述:近期给小孩打印课文,想到加注拼音方便小孩阅读。
目标:给每个汉字标注拼音,同时为了方便阅读每个汉字之间预留一个空格。(因为word注音如果不空格,拼音连在一起不便区分)
遇到的困难:word 2016的注音功能只能给大概二三十字一次性注音(未详细数到底多少),对于成百上千字的文档注音就很繁琐
解决方法:使用word中的宏,在网上搜集资料找到这篇文章:
https://www.cnblogs.com/DreamlikeAttic/p/3655863.html
对它做了一些修改,步骤如下:
1) 删掉了宏中分隔文字的片段:(有这段代码的宏处理速度会大大降低,且word总是崩溃)
2)使用word中替换命令,实现文字的自动分隔,(分隔速度极快)
Ctrl+H(替换快捷键)-> “空格^&”(不含引号)并把高级选项中的 “使用通配符”打开。
3)调好预期的字体,大小等等
4)运行如下宏
Sub AddPinYin()
'Author:MissileCat Date:20140410 version:1.0.0
' Addpinyin 宏
'为一篇完整的word文字加上标音标注
Dim tintTreatingCount As Integer
Dim tstrCharA As String
Dim tlngCurPos As Long
Dim tintA As Integer
Selection.WholeStory
tstrText = Selection.Text
tintTextLength = Selection.Characters.Count
tintlinestart = 1
tintTreatingCount = 0
Selection.GoTo What:=wdGoToHeading, Which:=wdGoToAbsolute, Count:=1
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}", 1
Application.Run MacroName:="FormatPhoneticGuide"
Selection.MoveRight unit:=wdCharacter, Count:=tintA
tintTreatingCount = 0
End If
Else
tintTreatingCount = tintTreatingCount + 1
End If
Next
End Sub
按照我这个顺序执行,最大的优点就是正确率高,(我实验的几次都没有出现错误),但是原作者的方法有很多漏注的字,但是也存在很大的缺点就是,速度慢。
原因是我先分隔汉字,然后注音,就是每个字都执行一次注音程序,而原作者方法是多个字一注音。
如有大神有更快的方法,希望给我评论。