Solved

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

Posted on 2014-04-02
3
1,293 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 49

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

777 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