|
昨晚本想对代码作些修改,但最终修没了。主要是后面用函数处理有问题,需改用查找替换办法。可试试如下代码,只是使用时需据实对代码作相应修改
- Sub test1()
- Dim myRange As Range
- Dim aSentence As Range
- Dim aField As Field
-
- Application.ScreenUpdating = False
- Set myRange = IIf(Selection.Type = wdSelectionIP, ActiveDocument.Content, Selection.Range)
- ActiveDocument.ActiveWindow.View.ShowFieldCodes = False
- For Each aSentence In myRange.Sentences
- If aSentence.Text Like "*[一-龥]*" Then
- aSentence.Select
- Dialogs(986).Show 1
- End If
- Next:
-
- ' 以下循环语句可用于调整拼音文本的设置参数(开关),如有必要,请据实自行测试后设定替换方案
- ' 显示域代码后即可看到EQ域的代码文本,其中包括原设置中的各项参数,可据实修改代码中的参数文本
- ' 代码文本中jc,hps,up加数字分别表示对齐、偏移量
- For Each aField In myRange.Fields
- If aField.Type = wdFieldFormula Then
- With aField.Code.Find
- .MatchWildcards = True
- .Execute findtext:="( hps)[0-9]{1,}", replacewith:="\116 ", Replace:=wdReplaceAll
- .Execute findtext:="(\up )[0-9]{1,}", replacewith:="\114", Replace:=wdReplaceAll
- .Execute findtext:="Font:宋体", replacewith:="Font:仿宋", Replace:=wdReplaceAll
- .Font.Size = 7
- .Replacement.Font.Size = 10
- .Execute findtext:=Empty, replacewith:=Empty, Replace:=wdReplaceAll
- End With
- End If
- Next
- Application.ScreenUpdating = True
- End Sub
复制代码
如用SendKeys语句操作,可试试如下代码:
- Sub test2()
- Dim myRange As Range
- Dim aSentence As Range
-
- Application.ScreenUpdating = False
- Set myRange = IIf(Selection.Type = wdSelectionIP, ActiveDocument.Content, Selection.Range)
- ActiveDocument.ActiveWindow.View.ShowFieldCodes = False
- For Each aSentence In myRange.Sentences
- If aSentence.Text Like "*[一-龥]*" Then
- aSentence.Select
- SendKeys "%L{DOWN}%F仿宋%O{UP 2}%S8{ENTER 2}", True
- Application.Run "FormatPhoneticGuide"
- End If
- Next
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|