批量处理word里面表格的空白行

1,随便打开一个word文档。

2,按下Alt + F11 VBA编辑器,在左侧的「工程资源管理器」窗口中找到Normal 项目,右键选择插入->模块。

弹出一下弹窗

3,输入一下代码

代码:

vbscript 复制代码
Sub RemoveEmptyTableRows()
    Dim tbl As Table
    Dim row As Row
    Dim cell As Cell
    Dim i As Long
    
    For Each tbl In ActiveDocument.Tables
        ' 从最后一行向前遍历,避免删除导致索引变化
        For i = tbl.Rows.Count To 1 Step -1
            Set row = tbl.Rows(i)
            Dim isEmptyRow As Boolean
            isEmptyRow = True
            For Each cell In row.Cells
                ' 去除单元格中的控制字符并检查是否为空
                Dim cellText As String
                cellText = Replace(Replace(cell.Range.Text, Chr(13), ""), Chr(7), "")
                If Trim(cellText) <> "" Then
                    isEmptyRow = False
                    Exit For
                End If
            Next cell
            If isEmptyRow Then
                row.Delete
            End If
        Next i
    Next tbl
    MsgBox "处理完成!"
End Sub

Ctrl+S保存一下

然后就可以关掉这个窗口,在回到word界面

4,返回Word界面,按下 Alt + F8,选择RemoveEmptyTableRows,再点击运行,即可完成空白行的批处理。

运行结果

相关推荐
ComPDFKit12 小时前
PDF转Word后,每行都成一段?先分清断段、文本框和扫描页
pdf·word
thethefighter14 小时前
快速预览Word、WPS秒开,支持空格弹窗
linux·word·wps·快速预览·空格弹窗·nhdeepview
SunnyDays101116 小时前
Java 操作 Word 脚注和尾注:添加、读取与删除
java·word
SunnyDays101116 小时前
Java 为 Word 添加页码:隐藏封面页码、从指定页开始编号、奇偶页页码设置等
java·word·页码
Eiceblue16 小时前
用 Python 给 Word 文档加水印:文字、图片与批量处理
开发语言·vscode·python·word
Metaphor6922 天前
使用 Python 在 Word 文档中添加、修改和删除变量
python·word
Monte05392 天前
word 如何让mathtype公式居中,公式编号右对齐
word
2501_930707782 天前
如何使用C#代码替换 Word 文档中的文本
word
Metaphor6923 天前
轻松使用 Python 将 RTF 转换为 Word(含批量转换与格式互转)
python·word·rtf
IHaveADiscovery3 天前
AI代劳Word表格线条:先搞懂术语再动手
人工智能·word