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]

12 comments

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


  2. Hi. Just wanted you to know that you saved my life.


  3. “I have NO idea why you might want to do this, but figured I’d share these two macros.. ”

    I used the first! Thanks!


  4. Great for stripping down a document for database import when you don’t want the tables and figures to mess up the import process! Great macros, thanks. Would be helpful too if there was a simple way to insert text such as “table placeholder” in the location where the tables and figures are deleted


  5. How do you delete all of the tables, but keep the text that is in them? I have about 200 tables, so doing them manually is out of the question because this will need done daily.


  6. Hi Austin

    I don’t know that you can, except manually. That said, you might be able to record a macro that converts a table to text, then jumps to the next table and converts that etc. It should be easy enough to record a macro that converts a table to text, but as far as finding each table via a macro, I wouldn’t know how to do that.

    However, you can ask your question on the Microsoft Answers forum for Word (http://answers.microsoft.com/en-us/office/forum/word) — one of the MVPs or gurus there who is full bottle on macros may be able to help.

    –Rhonda


  7. Thanks, this is perfect! It is very useful for deleting tables and figures before importing Real Text .rtf documents into IBM Rational DOORS.


  8. Hello – I have a very basic macro – here it is:
    Sub tableDelete()

    ‘ tableDelete Macro
    ‘Dim nTables As Integer
    nTables = ActiveDocument.Tables.Count
    ActiveDocument.Tables(nTables).Delete

    End Sub ——–I would like this macro to only work once (for example on click – only 1 table is deleted) – then the macro stops working.


  9. Invaluable for me!! I needed to remove all tables from a university assignment to find our the true word count.

    Thanks!


  10. God Bless you. Your macro worked like a charm. I needed to delete thousands of tables from my dissertation document to create a compact version and this was a life saver.

    Thanks much.


  11. Is there a way to do this only with a certain range?


  12. Hi Latricia

    I expect you could do just a range if you put a ‘selection’ statement into the macro. However, my macro knowledge is basic, so I don’t know how to do that.

    Perhaps ask your question on the Microsoft Answers forum for Word (http://answers.microsoft.com/en-us/office/forum/word) — one of the MVPs or gurus there who is full bottle on macros may be able to help.

    –Rhonda



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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: