|
楼主 |
发表于 2009-3-21 13:16
|
显示全部楼层
'测试文档为朱自清先生的《春》
'根据sylun兄提供KSPPtoASCII3修改
'sylun兄已经发给我最快的测试文档仅3秒多。(因电脑而异)没有得到授权,不宜公开代码
'得到了论坛朋友们的帮助。这个是原来的改进版,改用倒序查找的方法速度达到5秒。
'2009.3.21 wjhere@126.com
Dim strW As String
Dim strP As String
Dim myR, myRr As Range
Dim S#
Dim wL, K As Integer
S = Timer
On Error Resume Next
Application.ScreenUpdating = False '关闭屏幕刷新
ActiveDocument.ActiveWindow.View.ShowFieldCodes = True '关闭域代码显示
With ActiveDocument.Content.Find
.ClearFormatting
.Text = "[一-﨩]{1,}" '查找一个以上的中文字符
.MatchWildcards = True
.Forward = False '使用通配符,倒序查找
Do While .Execute
Set myRr = .Parent '找到的中文字符串区域
wL = myRr.Words.Count
For K = wL To 1 Step -1 '使用倒序标注拼音
Set myR = myRr.Words(K)
strW = myR.Text
strP = HzToPy(strW)
myR.PhoneticGuide Text:=strP, Alignment:=wdPhoneticGuideAlignmentCenter, _
Raise:=15, FontSize:=14
myR.Collapse wdCollapseStart
Next
myRr.Collapse wdCollapseStart ' 折叠到开头,避免二次查找
Loop
End With
Set myR = Nothing
Set myRr = Nothing
ActiveDocument.ActiveWindow.View.ShowFieldCodes = False
Application.ScreenUpdating = True
MsgBox "用时 " & Timer - S & " 秒!", vbInformation, "飞快标注音标" |
|