The following should work:
Code:
Sub BatchDelete()
Dim strFile As String
Dim strPath As String
Dim oDoc As Document
Dim iFld As Integer
Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
.Title = "Select folder and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
MsgBox "Cancelled By User", , "List Folder Contents"
Exit Sub
End If
strPath = fDialog.SelectedItems.Item(1)
If Right(strPath, 1) <> "\" Then strPath = strPath + "\"
End With
strFile = Dir$(strPath & "*.*")
While strFile <> ""
If Right(LCase(strFile), 4) = ".rtf" Or Right(LCase(strFile), 4) = "docx" Then
Set oDoc = Documents.Open(strPath & strFile)
DelTables oDoc, "AAA"
oDoc.Close SaveChanges:=wdSaveChanges
End If
strFile = Dir$()
Wend
lbl_Exit:
Exit Sub
End Sub
Private Sub DelTables(oDoc As Document, sFind As String)
Dim oTable As Table
Dim lCount As Long
If oDoc.Tables.Count > 0 Then
For lCount = oDoc.Tables.Count To 1 Step -1
If InStr(1, oDoc.Tables(lCount).Range, sFind) > 0 Then
'Debug.Print oDoc.Name & vbTab & "Table " & lCount
oDoc.Tables(lCount).Delete
End If
Next lCount
End If
End Sub