Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 02-04-2022, 11:15 AM
nmkhan3010 nmkhan3010 is offline Batch Table Deletions Based on a string. Windows 10 Batch Table Deletions Based on a string. Office 2016
Novice
Batch Table Deletions Based on a string.
 
Join Date: Feb 2020
Posts: 21
nmkhan3010 is on a distinguished road
Default Batch Table Deletions Based on a string.

Hi,



I had copied the below code from the previous posts, it working effectively only when the find string is unique in the document, could you please modify the below code as if the find string is more than one time, then take the first match string as a base to delete the above tables. but the below code is taking the last match case as a base to delete the above tables.

Please add a browse option to delete the unncessary tables in a folder having more than 20 docs.

Please ammend the below changes :

Batch processing of docs in a folder to delete the tables in a folder (Format .rtf, .docx)

ADD:
Dim SourcePath As String
SourcePath = InputBox("PLEASE ENTER PATH", "SOURCE PATH") & ""

Below code is taking last match case as base, please change it to first match case a base to delete the above tables.

Please find the attachment zip folder having more documents and find string is available more than one time.

AAA is available in Table 3 & Table 6 but the below code is deleting a tables above to the table 6, but my need is to delete a tables on first match case which is above to the table 3.

Please find the existing code below:

Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Rng As Range
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "AAA"
    .Replacement.Text = ""
    .Format = False
    .Forward = False
    .Wrap = wdFindStop
    .MatchCase = True
    .MatchWholeWord = False
    .MatchWildcards = False
  End With
  Do While .Find.Execute
    If .Information(wdWithInTable) = True Then
      Set Rng = ActiveDocument.Range(0, .Tables(1).Range.Start)
      Do While Rng.Tables.Count > 0
        Rng.Tables(1).Delete
      Loop
      Exit Do
    End If
    .Collapse wdCollapseStart
  Loop
End With
Application.ScreenUpdating = True
End Sub
Thanks in advance.
Attached Files
File Type: zip Test.zip (167.2 KB, 9 views)
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 05:10 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