怎么为整篇word文字添加拼音标注
时间:2023-12-12 05:02:49
由于对word宏命令不太熟悉,我将个任务分解为三部分,第一,了解光标的移动指令;第二,了解加拼音的命令;第三,对排版进行一些美化调整。
第一点,并不复杂,简单录制一个宏,移动一下光标,就很清楚地看到移动的指令了。
Selection.MoveRightunit:=wdCharacter,Count:=1,Extend:=wdExtend
接下来,我在msdn简单浏览了一下selection对象以及一些move前缀的方法,初步了解了一些移动的指令。
第二点,我右键点了下菜单,在自定义菜单中找了“拼音标准”对应的命令FormatPhoneticGuide,以此为关键字进行搜索,很快就得到了在宏中使用的简单调用方法,但这个方法我觉得不科学,如果有软件处理响应时间跟不上,很容易就会崩溃,但没找到更好的方法:
SendKeys"{enter}",2‘模拟键盘输入,2是等待时间,因为加拼音标注的对话框调用在后面,为了正确向它发出回车键信息,要等几秒,事实上这个值越大越安全,但等待时间太长会影响程序的运行效率,这个方法我认为不太好,但没有找到FormatPhoneticGuide的其它信息,也就将就使用这个笨方法了!Application.RunMacroName:="FormatPhoneticGuide"
第三点,为了让加了拼音后的文字容易阅读,我决定每个字之间都加上一个空格,否则的话,拼音全挤在一起,会令小孩在拼读时迷惑,这相当简单,录制一个宏,就按一下键盘箭头右移动,然后打个空格就好了,在程序中可以将这个动作循环一下。
Addpinyin的宏很快就写好,我一句句单步了一下,没有什么意外,效果还不错,直接上结果图。喜欢的朋友可以也可以看看完整的宏代码。
代码如下:复制内容 |
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}", 2 Application.Run MacroName:="FormatPhoneticGuide" Selection.MoveRight unit:=wdCharacter, Count:=tintA tintTreatingCount = 0 End If Else tintTreatingCount = tintTreatingCount + 1 End If Next '为每个字都加上空格 Selection.GoTo What:=wdGoToHeading, Which:=wdGoToAbsolute, Count:=1 'Selection.HomeKey unit:=wdStory For tintloopx = 1 To tintTextLength Selection.MoveRight unit:=wdCharacter, Count:=1 Selection.TypeText Text:=" " Next MsgBox "任务成功完成" ' .Range.PhoneticGuide Text:="lǐ", Alignment:= _ ' wdPhoneticGuideAlignmentOneTwoOne, Raise:=15, FontSize:=8, FontName _ ' :="宋体" End Sub |
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
AutoCAD 2009快捷键有什么?AutoCAD2009常用快捷键介绍
![](https://img.aspxhome.com/file/2023/7/a331822_0s.jpg)
Win10 1909开机黑屏很久才进入系统怎么办?Win10
![](https://img.aspxhome.com/file/2023/4/a310870_0s.jpg)
解决Mac电脑上chrome浏览器无法访问网络的方法
![](https://img.aspxhome.com/file/2023/7/a205947_0s.jpeg)
在桌面养只捣蛋鹅,让 Desktop Goose 陪你一起用Mac
![](https://img.aspxhome.com/file/2023/1/a205911_0s.jpeg)
给苹果电脑新手推荐的一些好用常用的Mac软件 !
如何解决office 2007 禁止宏提示“宏已被禁用”的问题
WPS Excel 聊聊DAYS360 函数
![](https://img.aspxhome.com/file/2023/9/a187339_0s.jpg)
如何清除Win10账户头像设置记录 Win10恢复默认头像详细图文步骤
![](https://img.aspxhome.com/file/2023/28/a247987_0s.jpg)
Win11/10 新增功能"Peek 快速查看"? Win11打开Peek 快速查看的技巧
![](https://img.aspxhome.com/file/2023/28/a240352_0s.jpg)
Win10系统自带浏览器无法打开网页怎么办?
![](https://img.aspxhome.com/file/2023/28/a244720_0s.jpg)
Win11的运行怎么打开?Win11的运行打开方法
![](https://img.aspxhome.com/file/2023/27/a237361_0s.jpg)
Cursorfx怎么改鼠标样式设置
![](https://img.aspxhome.com/file/2023/7/a328549_0s.png)
【彻底解决】共享打印机时报错误代码0x0000011b或0x00000709的问题
![](https://img.aspxhome.com/file/2023/1/a273530_0s.png)
Win11输入法的候选区消失了怎么解决?
![](https://img.aspxhome.com/file/2023/1/a280876_0s.jpg)
Win7系统打开snmp服务的详细操作步骤
![](https://img.aspxhome.com/file/2023/4/a313252_0s.jpg)
360安全卫士怎么设置不自动修复漏洞
![](https://img.aspxhome.com/file/2023/8/a338546_0s.jpg)
微软用Win10推广SwiftKey输入法:主打剪贴板手机电脑云同步
![](https://img.aspxhome.com/file/2023/5/a315104_0s.jpg)
Win10专业版显示此站点不安全的解决方法
![](https://img.aspxhome.com/file/2023/1/a277568_0s.png)
ES文件浏览器如何使用?ES文件浏览器连接电脑教程
![](https://img.aspxhome.com/file/2023/9/a340888_0s.jpg)
win10输入法切换不了怎么办?
![](https://img.aspxhome.com/file/2023/4/a311011_0s.jpg)