Consulting

Results 1 to 3 of 3

Thread: How can I delete all tables with a particular style in word?

  1. #1
    VBAX Newbie
    Joined
    Apr 2018
    Posts
    2
    Location

    How can I delete all tables with a particular style in word?

    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:
    2018-04-05 18-28-36.jpg

    basically just id numbers, which change for every table.

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

    Matt

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    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.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    VBAX Newbie
    Joined
    Apr 2018
    Posts
    2
    Location
    Wow, amazing, that worked perfectly, thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •