此类问题,用查找与替换也许也能解决,只是,如果使用VBA来解决,则也是一个容易的事。
以下代码供参考:
'* +++++++++++++++++++++++++++++
'* Created By I Love You_Word!@ExcelHome 2005-4-17 6:36:11
'仅测试于System: Windows NT Word: 10.0 Language: 2052
'^The Code CopyIn [ThisDocument-ThisDocument]^'
'* -----------------------------
Option Explicit '显式变量声明
Option Compare Text '不区分大小写
Sub ExampleToReplce()
Dim aWord As Range, aChar As Range, aCharCount As Integer, ReplaceCount As Integer
On Error Resume Next '忽略错误
Debug.Print Now
Application.ScreenUpdating = False '关闭屏幕更新
For Each aWord In ThisDocument.Words '在本文档的词组中循环
If aWord Like "*#*" Then '如果该词组中含有数字
'如果其前面一个词为")"则将其设置为下标
If aWord.Previous(wdWord, 1) = ")" Then ReplaceCount = ReplaceCount + 1: aWord.Font.Subscript = True
aCharCount = 0 '初始化变量
For Each aChar In aWord.Characters '在该词组的单字中循环
If aChar Like "[a-z]" Then aCharCount = aCharCount + 1 '计数
'如果acharcount>0并且为数字
If aCharCount > 0 And aChar Like "#" Then ReplaceCount = ReplaceCount + 1: aChar.Font.Subscript = True
Next aChar '退出循环
End If
Next aWord '退出循环
Application.ScreenUpdating = True '恢复屏幕更新
Debug.Print Now
MsgBox "WORD 已进行了" & ReplaceCount & "次指定的格式设置,请您检查!", vbOKOnly + vbInformation
End Sub
'----------------------'实际运行:共设置1160个下标,用时不到1分钟.
'代码已在附件中,请ALT+F11查看该代码
rUM2r8gX.rar
(24.26 KB, 下载次数: 7)
[此贴子已经被作者于2005-4-17 6:37:07编辑过] |