Solved

Split currently selected table into several tables based on number of rows using VBA

Posted on 2014-04-02
3
1,311 Views
Last Modified: 2014-04-03
Dear Experts:

for the currently selected table I would like to run the following action using VBA:

Split the current table into several tables, i.e each row is converted into a single table with manual page breaks in between these newly created tables.

Example: currently selected table has 5 rows. After running the macro, 5 individual tables are created with 4 manual page breaks in between.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
0
Comment
Question by:AndreasHermle
  • 2
3 Comments
 
LVL 50

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39972325
Hi,

pls try

Sub Macro()

Set tbl = ActiveDocument.Tables(1)

For Idx = tbl.Rows.Count To 2 Step -1
    tbl.Cell(Idx, 1).Range.Select
    Selection.SplitTable
    Selection.InsertBreak Type:=wdPageBreak
Next
 With ActiveDocument.Content.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Text = Chr(13) & Chr(12) & Chr(13)
  .Replacement.Text = Chr(12)
  .Forward = True
  .Format = False
  .Execute Replace:=wdReplaceAll  ' <-- Use wdReplaceAll if required
End With
End Sub

Open in new window

EDIT Delete Paragraph Marks

Regards
0
 

Author Comment

by:AndreasHermle
ID: 39974347
Hi Rgonzo,

this macro works just great. Thank you very much for your great and professional support.

I slightly tweaked the code:

Line 3: Set tbl = Selection.Tables(1)

Regards, Andreas
0
 

Author Closing Comment

by:AndreasHermle
ID: 39974360
as always, professional solution provided by you.

Thank you very much. Regards, Andreas
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question