×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Remove Table but keep Content: Word 2003/2007

Remove Table but keep Content: Word 2003/2007

Remove Table but keep Content: Word 2003/2007

(OP)
Hello Champs

Is there a way to remove tables from a word document but keeping the content of each row by using VBA?

The Table isnt complext, simple rows (one coloumn) only.
Number of rows varies from 1-10 per table, multiple tables.

Problem: I cant use copy/paste plain text, as the content contains encoded URLs displayed as textlink.

Any hint?

RE: Remove Table but keep Content: Word 2003/2007

CODE

Dim oTable As Word.Table
For Each oTable In ActiveDocument.Tables
    oTable.Rows.ConvertToText Separator:=wdSeparateByParagraphs, _
        NestedTables:=True
Next
Will convert every table in the document to text, with each row separated by a paragraph mark.

Hyperlinks are retained exactly as they are.  They are not affected in any way.

Gerry
My paintings and sculpture

RE: Remove Table but keep Content: Word 2003/2007

(OP)
Thanks again for this one!
It really works incredebly fast!

Do you also know a method to delete the last two coloumns of the table prior removing the table and converting the containing text as per your above sample?

RE: Remove Table but keep Content: Word 2003/2007

Yes.  You are actioning each table, so simply delete the last two rows of that table.  Use the count of the rows.  Do it before you convert.

CODE

Dim oTable As Word.Table
Dim j As Long
For Each oTable In ActiveDocument.Tables
    j = oTable.Rows.Count
    oTable.Rows(j).Delete
    oTable.Rows(j - 1).Delete
    oTable.Rows.ConvertToText Separator:=wdSeparateByParagraphs, _
        NestedTables:=True
Next
Note that action like this is similar to actioning any Collection - you work backwards.  That is, you delete the last row first.

There are, like many things in VBA, alternative ways to do this.  You could select the last two rows, then delete.  You could make a Range of the last two rows, then delete.  However, I think using the row count is probably the easiest.

Gerry
My paintings and sculpture

RE: Remove Table but keep Content: Word 2003/2007




frankki,

Again, using your macro recorder would have given you a start on this one too.

Skip,

glasses
tongue

RE: Remove Table but keep Content: Word 2003/2007

Skip is right you know.  This could fairly easily be determined by using the macro recorder.  I suggest you try using it.

Gerry
My paintings and sculpture

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close