一个适用于 Word(Mac/Win 通用) 的 VBA 宏:把所有“上角标格式的 0‑9”以及 “Unicode 上角标数字 ⁰‑⁹” 批量删除。

一个适用于 Word(Mac/Win 通用) 的 VBA 宏:把所有"上角标格式的 0‑9"以及 "Unicode 上角标数字 ⁰‑⁹" 批量删除。

vbnet 复制代码
'========================================
' StripSupDigitsInWord.bas
' 删除 Word 文档中的所有上角标数字
'   1) 字体属性为 Superscript 的 0-9
'   2) Unicode 上角标数字 ⁰¹²³⁴⁵⁶⁷⁸⁹
'========================================
Option Explicit

Sub StripSupDigitsInWord()
    Dim sr As Range
    Application.ScreenUpdating = False
    
    ' 遍历正文、页眉页脚、脚注等所有 StoryRanges
    For Each sr In ActiveDocument.StoryRanges
        Call RemoveSupDigitsInRange(sr)
        Do While Not (sr.NextStoryRange Is Nothing)
            Set sr = sr.NextStoryRange
            Call RemoveSupDigitsInRange(sr)
        Loop
    Next sr
    
    Application.ScreenUpdating = True
End Sub


Private Sub RemoveSupDigitsInRange(ByVal rng As Range)
    Dim f As Find
    Dim codes As Variant
    Dim i As Long
    
    '------① 删掉"格式为上角标"的普通数字 0-9 ------'
    Set f = rng.Duplicate.Find
    With f
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = "[0-9]"          ' 匹配任意数字
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindStop
        .Format = True
        .Font.Superscript = True ' 仅找上角标
        .MatchWildcards = True
    End With
    
    Do While f.Execute
        f.Parent.Delete                ' 删除命中的字符
        rng.Collapse wdCollapseStart   ' 收缩到起点继续
        Set f = rng.Duplicate.Find     ' 重新绑定范围
        With f
            .Text = "[0-9]"
            .Replacement.Text = ""
            .Format = True
            .Font.Superscript = True
            .MatchWildcards = True
        End With
    Loop
    
    '------② 删掉 Unicode 上角标数字 ------'
    codes = Array(&H2070, &HB9, &HB2, &HB3, _
                  &H2074, &H2075, &H2076, &H2077, &H2078, &H2079)
    For i = LBound(codes) To UBound(codes)
        With rng.Find
            .ClearFormatting
            .Replacement.ClearFormatting
            .Text = ChrW(codes(i))
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindStop
            .Format = False
            .MatchWildcards = False
            .Execute Replace:=wdReplaceAll
        End With
    Next i
End Sub

使用步骤

  1. Word 打开文档 → 工具/开发工具 ▸ Visual Basic (⌥F11)

  2. 插入 ▸ 模块,粘贴上述代码。

  3. 关闭 VBE,回到 Word:开发工具 ▸ 宏,运行 StripSupDigitsInWord

  4. 建议先备份文档;如果开启了"修订",可先关闭或接受更改以提升速度。

想只处理选定文本,把 StripSupDigitsInWord 里遍历 StoryRanges 的部分改成:
Call RemoveSupDigitsInRange(Selection.Range) 即可。

相关推荐
缺点内向1 天前
C#: 告别繁琐!轻松移除Word文档中的文本与图片水印
c#·自动化·word·.net
徐小夕@趣谈前端1 天前
拒绝重复造轮子?我们偏偏花365天,用Vue3写了款AI协同的Word编辑器
人工智能·编辑器·word
kingwebo'sZone1 天前
C#使用Aspose.Words把 word转成图片
前端·c#·word
科技D人生1 天前
Vue.js 学习总结(20)—— Vue-Office 实战:word、pdf、excel、ppt 多种文档的在线预览
vue.js·word·vue-pdf·stylesheet·docx-preview·vue-office
weixin_416660072 天前
技术分析:豆包生成带公式文案导出Word乱码的底层机理
人工智能·word·豆包
骆驼爱记录2 天前
Word样式库不显示的8种修复方法
word·wps·新人首发
苍煜2 天前
超简单 poi-tl 学习博客:从0到1掌握Word生成(无需模板+模板填充)
学习·word
请为小H留灯2 天前
Word论文 封面、目录、页码设置步骤!(2026详细版教程)
毕业设计·word·论文格式
星尘库3 天前
在word中怎么把段落回车替换成空 删除空行
word
weixin_416660073 天前
AI 导出 Word 不正规?10 类文档样式模板(可直接套用,含字体/字号/行距/缩进)
人工智能·word·论文·排版·数学公式