|
本帖最后由 loquat 于 2014-4-30 23:36 编辑
- Public Sub 设置上下标(ByVal 查找字串$, ByVal 修改字串$, Optional ByVal 模式 As String = "上标")
- '调用方式:例如,要将全文的m3/s中的3设置为上标
- 'Call 设置上下标("m3/s","3","上标")
- Application.ScreenUpdating = False
- Dim aDoc As Document: Set aDoc = ActiveDocument
- Dim aRange As Range, a%, b%
- a = InStr(1, 查找字串, 修改字串)
- b = Len(修改字串)
- With Selection
- .HomeKey wdStory
- .Find.Text = 查找字串
- Do While .Find.Execute
- Set aRange = Selection.Range
- aRange.SetRange aRange.Start + a - 1, aRange.Start + a + b - 1
- aRange.Editors.Add wdEditorEveryone
- Loop
- End With
- aDoc.SelectAllEditableRanges wdEditorEveryone
- aDoc.DeleteAllEditableRanges wdEditorEveryone
- If 模式 = "上标" Then
- Selection.Font.Superscript = True
- ElseIf 模式 = "下标" Then
- Selection.Font.Subscript = True
- End If
- Application.ScreenUpdating = True
- End Sub
复制代码 TODO:
1.支持页眉页脚检索
2.支持文本框中检索
3.支持正则表达式
用处例如:要将全文的[1][2]……[11]改为上标,这就需要正则。 |
评分
-
2
查看全部评分
-
|