我正在尝试删除Word文档中不包含某些字符串的所有表,但未成功。
我当前的代码是:
Sub DeleteTablesIf()
Dim t As Table
For Each t In ActiveDocument.Tables
If t not contains "A" or "B" "C" then
t.Delete
End if
Next
End Sub
但是我不知道如何检查每个表中是否存在字符串“ A”,“ B”或“ C”。
在此先感谢您的帮助。
答案 0 :(得分:2)
未经测试:
Sub DeleteTablesIf()
Dim t As Table, i As Long, txt As String
'loop backwards when deleting
For i = ActiveDocument.Tables.Count To 1 Step -1
With ActiveDocument.Tables(i)
txt = .Range.Text
If Instr(txt, "A") = 0 And Instr(txt, "B") = 0 And _
Instr(txt, "C") = 0 Then
.Delete
End if
End With
Next
End Sub