Solved

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

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

Accepted Solution

by:
Rgonzo1971 earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
as always, professional solution provided by you.

Thank you very much. Regards, Andreas
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
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.

771 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

9 Experts available now in Live!

Get 1:1 Help Now