Delete Word table with macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I have a macro that should be deleting 2 tables in my document plus a logo.
I got it to delete one table, but i cant seem to get it to delete both tables
and the logo. The code looks like this: ActiveDocument.Tables(1).Delete

what is the proper code to get the macro to delete all tables in the
document plus the logo?

any help is appreciated.
 
One way - and this assumes there is some text after the 2 tables and the logo
- would be to write the macro so that you use "Find" to go to the spot before
the 1st table, then use "Find" again to go to the spot after the 2nd table
and logo.
 
Ok, I'm not sure how to write that macro since I'm new to macros. I've been
recording and then trying to edit the code. I found this one that is supposed
to delete the last table, but I cant figure out how to edit it so that it
deletes all of the tables plus the logo. this is the code:

Dim nTables As Integer
nTables = ActiveDocument.Tables.Count
ActiveDocument.Tables(nTables).Delete
 
The macro below will delete all tables in the active document:

Sub DeleteAllTables()

Dim oTable As Table

For Each oTable In ActiveDocument.Tables
oTable.Delete
Next oTable

End Sub

Note that your macro could be adjusted to delete all tables too (in the
current version, it will delete only the last table).

How to delete the logo depends on how and where it is inserted:
Is it “In line with text†or floating?
Is it in the main body of the document or, e.g., in the header?
Are there other graphics (drawings, pictures, etc.) in the document?

If the logo is the only graphic, inserted in the main body of the document
and "In line with text" (i.e. in the text layer of the document), the
following code line could be used to remove it:

ActiveDocument.InlineShapes(1).delete

If the wrapping style is any other than “In line with text†(i.e. the logo
is in the drawings layer of the document), you need to use “Shapes†instead
of “InlineShapesâ€:

ActiveDocument.Shapes(1).delete

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
Lane, The picture right now is set to In-line with text, however, I have
changed it a few times and I can still change it to accomodate the macro. I
will let you know how things worked out.

Thanks
 
Lene,

Thanks for the help, I really appreciate it. I have one more question, I'm
trying to remove two words from my document. One is the word "Telephone" and
the other is "facsimile." I have been trying to add this to the code you
provided but I keep getting errors. Any ideas how I can remove those two
words?

thanks,
 
Before I try to suggest a solution I would like to know a little more:
Are the two words found more than once - and in that case, do you want all
occurrences to be removed?
or
Are the two words found only once - maybe in a specific place in the document?

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top