Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 02-04-2022, 11:12 PM
gmayor's Avatar
gmayor gmayor is offline Batch Table Deletions Based on a string. Windows 10 Batch Table Deletions Based on a string. Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
 

Tags
batch deleting



Similar Threads
Thread Thread Starter Forum Replies Last Post
Table Deletions ranjan Word Tables 4 09-01-2021 02:58 PM
Batch Table Deletions Based on a string. Table deletions based on a string. nmkhan3010 Word Tables 3 05-03-2021 08:57 PM
Batch Table Deletions Based on a string. Batch applying a macro to remove Header and Footer using Batch Auto Addin Edszx Word VBA 2 05-27-2019 11:16 PM
VBA to provide text string with specific formating based on Drop down list (content control) MP1989 Word VBA 4 07-30-2018 02:40 AM
Batch change header text which is in a table marafubu Word VBA 1 05-16-2018 04:52 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:25 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft