Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When creating Microsoft Word-based forms there may be a need to have a form field repeated throughout the whole document. For instance, with a company name, you may want this information repeated automatically throughout the document rather than man…
This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now