批量处理word里面表格单元格中多余的回车符

实现代码

vbnet 复制代码
Sub DeleteTableCarriageReturns()
    Dim oTbl As Table
    Dim oCell As cell
    Dim oRng As Range
    
    ' 遍历文档中所有表格
    For Each oTbl In ActiveDocument.Tables
        ' 遍历表格中的每个单元格
        For Each oCell In oTbl.Range.Cells
            Set oRng = oCell.Range
            oRng.End = oRng.End - 1 ' 排除单元格结束标记
            
            ' 在单元格范围内执行替换
            With oRng.Find
                .Text = "^p"    ' 匹配段落标记
                .Replacement.Text = ""
                .Forward = True
                .Wrap = wdFindStop  ' 仅在当前范围操作
                .Execute Replace:=wdReplaceAll
            End With
        Next oCell
    Next oTbl
End Sub

代码使用方法见批量处理word里面表格的空白行

相关推荐
AI偶然6 小时前
AI智能体|扣子(Coze)搭建【一键转换为Word/pdf/Excel】工作流保姆级教学
人工智能·pdf·word
zdlu20 小时前
Deepseek输出的内容如何直接转化为word文件?
word·deepseek
救救孩子把1 天前
Spring Boot 集成Poi-tl实现动态Word文档生成
spring boot·word
生态笔记1 天前
word选中所有的表格——宏
经验分享·word
inxunoffice1 天前
如何一键批量删除多个 Word 文档中的页眉和页脚
word
生态笔记1 天前
word表格批量操作——宏
经验分享·word
inxunoffice1 天前
如何批量在多个 Word 文档末尾添加广告页面
word
开开心心就好2 天前
实用电脑工具,轻松实现定时操作
python·学习·pdf·电脑·word·excel·生活
Clarkbrave2 天前
PHP使用pandoc把markdown文件转为word
开发语言·word·php
da-peng-song4 天前
python学习—详解word邮件合并
python·学习·word