我一直在努力使用一个字宏来删除空行,其中一个" $"存在。下面的代码可以工作,但仅适用于选定的表,如何让代码循环遍历整个文档并从所有页面中删除空行。
Option Explicit
Sub TEST()
Dim i As Long
With Selection.Tables(1)
For i = .Rows.Count To 1 Step -1
If Len(.Cell(i, 2).Range.Text) = 3 And Left(.Cell(i, 2).Range.Text, 1) = "$" Then
.Rows(i).Delete
End If
Next i
End With
End Sub
答案 0 :(得分:3)
由于未提供,因此未在与OP相同的数据集上进行测试。
Option Explicit
Sub TEST()
Dim tbl As Table
Dim mDoc As Document
Dim oRow As Row
Set mDoc = ActiveDocument
For Each tbl in mDoc.Tables
For Each oRow In tbl.Rows
If Len(oRow.Cells(2).Range.Text) = 3 And _
Left(oRow.Cells(2).Range.Text, 1) = "$" Then
oRow.Delete
End If
Next oRow
Next tbl
End Sub