h1

Word: Macros to delete all tables and figures

June 23, 2011

I have NO idea why you might want to do this, but figured I’d share these two macros — one is to delete all tables, and the other is to delete all figures from a Word document.

The macro to delete all tables is from Allen Wyatt’s Word VBA Guidebook (http://store.tips.net/T010353_Word_VBA_Guidebook_Table_of_Contents.html); the one to delete all figures was one I created based on the tables one. However, it wasn’t easy! Unlike tables (Table object), figures aren’t under normal words like ‘figure’, ‘picture’, ‘photo’, ‘diagram’, or ‘image’ — no, they are part of the InlineShape object! That bit of information took some time to find.

Please use with caution — these macros WILL delete every table or figure, except those in your document’s headers and footers.

Macro to delete all tables in a document

Sub TablesDeleteAll()
    Dim tbl As Table
    For Each tbl In ActiveDocument.Tables
        tbl.Delete
    Next tbl
End Sub

Macro to delete all figures in a document

Sub FiguresDeleteAll()
    Dim fig As InlineShape
    For Each fig In ActiveDocument.InlineShapes
        fig.Delete
    Next fig
End Sub

[Links last checked June 2011]

You can buy me a coffee if this tip helped you Has this tip helped you? saved you time? saved your skin? You can thank me by clicking on the cup and buying me a coffee. (An E-Junkie shopping cart page will open where you can pay for my coffee via PayPal.)

One comment

  1. Delete all tables is exactly what I wanted!!!! Thanks!



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 104 other followers