|
各位大神晚上好,如附图照片所示,我要批量(三四百份)删除测试报告空白行。目前已经有部分代码了,单个文件删除没有问题,当相同文件夹下删除就报错了,麻烦各位帮忙看看咋回事(个人办公用WPS软件),非常感谢。
报错信息:无法访问此集合中单独的行,因为表格有纵向合并的单元格。个人新手整了两天都不行。
代码在这:
Sub DeleteEmptyRowsInTables()
Dim tbl As Table
Dim i As Integer, ff, MyPath, k
MyPath = ActiveDocument.Path & "\"
ff = Dir(MyPath & "*.docx*")
k = 2
Do While ff <> ""
For Each tbl In ActiveDocument.Tables
i = i + 1
'Check if table is not the first table
If i > 1 Then
'Loop through each row in table
Dim row As row
For Each row In tbl.Rows
'Check if second to fourth column is empty
If Len(Trim(row.Cells(2).Range.Text)) = 2 _
And Len(Trim(row.Cells(3).Range.Text)) = 2 _
And Len(Trim(row.Cells(4).Range.Text)) = 2 Then
'Delete row if all columns are empty
row.Delete
End If
Next row
End If
Next tbl
k = k + 1
Loop
MsgBox "删除空白表格完成!"
End Sub
|
|