|
楼主,由于搞不清你到底是将m2/m3还是m^2/m^3变为上标,所以,我综合考虑了这种情况,由于水平有限,宏代码不够精简、高级,但似乎测试通过,你试试吧(操作前请备份原文件):- Sub 设置上标()
- '功能:将 m2/m3 或 m^2/m^3 设置为上标;如果未选定区域则选择全文。
- Dim myRange As Range
- If Selection.Type = wdSelectionIP Then Selection.WholeStory '如果未选则全选
- Set myRange = Selection.Range
- myRange.Find.Execute FindText:="^", ReplaceWith:="", Replace:=wdReplaceAll '删除选定区域^字符(全部替换为无)
- myRange.Select
- '
- '设置m2为上标
- Do
- Selection.Find.ClearFormatting
- With Selection.Find
- .Text = "m2"
- .Replacement.Text = ""
- .Forward = True
- .Wrap = wdFindStop
- .Format = False
- .MatchCase = False
- .MatchWholeWord = False
- .MatchByte = True
- .MatchWildcards = False
- .MatchSoundsLike = False
- .MatchAllWordForms = False
- End With
- Selection.Find.Execute
- Selection.MoveStart Unit:=wdCharacter, Count:=1
- Selection.Font.Color = wdColorRed '此语句设置上标为红色,也可以不要!
- Selection.Font.Superscript = True
- Selection.MoveRight Unit:=wdCharacter, Count:=1
- Loop Until Selection.Find.Found = False
- '
- '设置m3为上标(与上段代码相同)
- myRange.Select
- Do
- Selection.Find.ClearFormatting
- With Selection.Find
- .Text = "m3"
- .Replacement.Text = ""
- .Forward = True
- .Wrap = wdFindStop
- .Format = False
- .MatchCase = False
- .MatchWholeWord = False
- .MatchByte = True
- .MatchWildcards = False
- .MatchSoundsLike = False
- .MatchAllWordForms = False
- End With
- Selection.Find.Execute
- Selection.MoveStart Unit:=wdCharacter, Count:=1
- Selection.Font.Color = wdColorRed '此语句设置上标为红色,也可以不要!
- Selection.Font.Superscript = True
- Selection.MoveRight Unit:=wdCharacter, Count:=1
- Loop Until Selection.Find.Found = False
- End Sub
复制代码 |
|