#1
|
|||
|
|||
Table deletions based on a string.
Table deletions based on a string.
If a string “AAA” is available in the any table in any cell, then delete all the above tables excluding from “AAA” found table and all the below tables. Doc format: ".docx" Suppose they are 1 to 50 tables in a document, AAA found in table 25 then delete all the tables from 1 to table 24. Purpose is to delete the unnecessary tables base on that strings… Please help me in this regards and thanks in advance. Please find a attachment. |
#2
|
||||
|
||||
For example:
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
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Deleting the above and below tables
Thank you so much its working great and highly appreciated for your work.
Adding another query related to the same task... Like wise is it possible to delete the above and below the tables based on a matched strings in a table. Example: In a document having 100 tables; if match string is available in table 20 then delete all the above tables from table 1 to table 19 & another match string is available in table 50 then delete all the below tables from 51 to table 100. then document will have only the relevant tables from table 20 to table 50 & we had deleted the unnecessary tables manually, can we automate this task, please suggest me ... Thanks in advance..... |
#4
|
||||
|
||||
How about a little effort on your part. The code I posted already gives you the clues for how to do that.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Tags |
table deletions |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Track Changes Problem - lines from comments & deletions don't go to right text. | Emmryss | Word | 6 | 01-17-2019 05:37 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 |
Stop Show Up Formatting and Insertions&Deletions | theta30 | Word | 6 | 03-20-2014 03:57 PM |
Macro to format additions deletions when Comparing Files | Alphacsulb | Word VBA | 0 | 08-19-2013 03:03 PM |
inserting a string of data into an MS Word table??? | matto | Word VBA | 0 | 07-16-2010 09:35 AM |