|
以前写的代码,很明显有点Low
- 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
- Sub 执行()
- 设置上下标 "m2", "2", "上标"
- 设置上下标 "m3", "3", "上标"
- End Sub
复制代码 |
|