一个适用于 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) 即可。

相关推荐
A Everyman17 小时前
Java 高效生成 Word 文档:poi-tl 的使用
java·pdf·word·poi-tl
AI英德西牛仔17 小时前
ChatGPT和Gemini导出word排版
人工智能·ai·chatgpt·word·deepseek·ds随心转
reasonsummer1 天前
【办公类-142-03】20260304插班生word转长表EXCLE(3)从word表格按行导出列表,提取索引内容。写入EXCLE长表,另存有名字的文件名
word
深藏功yu名2 天前
Day22:RAG 王炸进阶!多格式文档 (PDF_Word)+ 多文档知识库搭建
人工智能·python·pycharm·langchain·pdf·word·rag
傻啦嘿哟2 天前
使用 Python 实现 Word 文档文本格式化全解析
开发语言·python·word
luyun0202023 天前
Word题库转换,吾爱出品
windows·word·figma
热爱生活的五柒3 天前
如何将word中latex公式复制到另一个文档中
word·latex
萝卜白菜。3 天前
TongWeb7.0配置tongweb-web.xml修改jsessionid名及其值的长度
xml·前端·word
YXWik63 天前
Linux 环境 libreoffice 执行word转pdf 中文乱码问题
linux·pdf·word
pingan87875 天前
试试 docx.js 一键生成 Word 文档,效果很不错
开发语言·前端·javascript·ecmascript·word