PDA

View Full Version : [SOLVED:] How can I delete all tables with a particular style in word?



mmickle
04-05-2018, 09:30 AM
Hello,

I am able to figure out how to delete all tables using a macro in word but i cannot for the life of me figure out how to specify a particular type of table to delete. The table that i would like to delete uses a particular style for the text, but unfortunately the actual contents in text is in now way consistent. Is this even possible?

Here is an example of how the table looks:
21979

basically just id numbers, which change for every table.

Any help or a point in the right direction would really help thank you.

Matt

macropod
04-05-2018, 02:01 PM
Try something based on:

Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Format = True
.Style = "MyStyle"
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Wrap = wdFindStop
.Execute
End With
Do While .Find.Found
If .Information(wdWithInTable) = True Then .Tables(1).Delete
.Collapse wdCollapseEnd
.Find.Execute
Loop
End With
Application.ScreenUpdating = True
End Sub
Simply change 'MyStyle' to match your Style name.

mmickle
04-06-2018, 12:12 AM
Wow, amazing, that worked perfectly, thank you!