27 | 07 | 2017

VisibleVisual.com | Word VB Articles

Delete Tables by Title

With the function below it's possible to delete tables by there title. The code loops through all tables (and first line tables within a table) and deletes it when the tables title matches the searched table. 

A table title can be set in a word template by going to the Table Properties > Alternative Text > Title. 

Word Table Title

 

Code:

Function DeleteTableByTitle(ByVal Worddoc As Word.Document, ByVal Title As String)
On Error GoTo errorhandler


Dim tbl As Table
Dim tbl2 As Table

For Each tbl In Worddoc.Tables
        
        If tbl.Title = Title Then tbl.Delete: GoTo volgende2
        
        For Each tbl2 In tbl.Tables
            If tbl2.Title = Title Then tbl2.Delete
        Next tbl2
        
volgende2:
Next tbl

Exit Function
errorhandler:
MsgBox Title
End Function

Download the sample WORD Document where we explain this code.

DOWNLOAD HERE

 
Login

Sign up now and upload your code to the website.

Help us to continue.....
Statistics
Articles View Hits
2311509
Latest Articles