批量处理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,再点击运行,即可完成空白行的批处理。

运行结果

相关推荐
wh393320 小时前
使用Python将PDF转换成word、PPT
python·pdf·word
bu_shuo3 天前
word表格中使用公式
word·表格
不坑老师3 天前
利用不坑盒子的Copilot,快速排值班表
microsoft·word·powerpoint·excel·copilot·wps
开开心心就好3 天前
批量PDF转换工具,一键转换Word Excel
开发语言·前端·学习·pdf·电脑·word·excel
RainSerein4 天前
Laravel8中使用phpword生成word文档
word·php·laravel
qq_393828224 天前
办公文档批量打印器 Word、PPT、Excel、PDF、图片和文本,它都支持批量打印。
windows·word·powerpoint·excel·软件需求
_oP_i13 天前
实现 “WebView2 获取word选中内容
开发语言·c#·word
LENG_Lingliang14 天前
word出现由WPS切换后公式异常无法删除的情况处理
word·wps·mathtype
贤和兄14 天前
使用docx4j 实现word转pdf(linux乱码处理)
linux·pdf·word
开开心心就好15 天前
高效批量转换Word到PDF的方法
javascript·安全·智能手机·pdf·word·objective-c·lisp