1,随便打开一个word文档。
2,按下Alt + F11 VBA编辑器,在左侧的「工程资源管理器」窗口中找到Normal 项目,右键选择插入->模块。
弹出一下弹窗
3,输入一下代码
代码:
Sub RemoveEmptyTableRows()Dim tbl As TableDim row As RowDim cell As CellDim i As LongFor Each tbl In ActiveDocument.Tables' 从最后一行向前遍历,避免删除导致索引变化For i = tbl.Rows.Count To 1 Step -1Set row = tbl.Rows(i)Dim isEmptyRow As BooleanisEmptyRow = TrueFor Each cell In row.Cells' 去除单元格中的控制字符并检查是否为空Dim cellText As StringcellText = Replace(Replace(cell.Range.Text, Chr(13), ""), Chr(7), "")If Trim(cellText) <> "" ThenisEmptyRow = FalseExit ForEnd IfNext cellIf isEmptyRow Thenrow.DeleteEnd IfNext iNext tblMsgBox "处理完成!"
End Sub
Ctrl+S保存一下
然后就可以关掉这个窗口,在回到word界面
4,返回Word界面,按下 Alt + F8,选择RemoveEmptyTableRows,再点击运行,即可完成空白行的批处理。
运行结果