#1
|
|||
|
|||
adding tables based on a number given in a form
Dear forum,
I would like to have a macro that inserts tables based on the number of tables that I need. This number will be above the table in a form field. Please see attached document and here below: Number of persons: 5 Person 1 Text1 Text2 Text3 And I type 5, I would like a macro to copy and paste same table 5 times. The table is part of a document that includes more information. Thank you so much for any help you can give. Coba |
#2
|
|||
|
|||
Replace Person 1 with Person {Seq TblNum}
Note that is a sequence field and the braces are created using Ctrl+F9 Bookmark the entire Person # paragraph and table. Code:
Sub ScratchMacro() 'A basic Word macro coded by Greg Maxey Dim oRng As Range Dim oTbl As Table Dim lngIndex As Long Set oRng = ActiveDocument.Bookmarks("PersonTable").Range oRng.Copy oRng.Collapse wdCollapseEnd oRng.InsertBefore vbCr oRng.MoveStart wdParagraph, 1 For lngIndex = 1 To ActiveDocument.FormFields("Tekst1").Result - 1 oRng.Paste oRng.Collapse wdCollapseEnd oRng.InsertBefore vbCr oRng.MoveStart wdParagraph, 1 Next ActiveDocument.Fields.Update lbl_Exit: Exit Sub End Sub |
#3
|
|||
|
|||
Thank you so much, Greg, for your help.
|
#4
|
|||
|
|||
I am wondering, how can I have the each table name has
"Person1" and the next "Person2" etc...? Actually, what I would like to have is to use VBA to count the number of tables that are created and to number each of the tables: "Table 1", "Table 2", "Table 3", etc. Thanks for your help. |
#5
|
|||
|
|||
The problem is solved
|
#6
|
|||
|
|||
ActiveDocument.Fields.Update as the last active line in the code is one solution as I had already created the SEQ fields in the document that I attached.
|
Tags |
form field, table, word vba. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Automatically adding new rows based on form field | tejaspareek | Word VBA | 4 | 04-17-2015 05:35 AM |
Adding sums from simuliar tables from different sheets. | LameDuck | Excel | 0 | 12-04-2014 08:57 PM |
Adding text to after a bookmark based on drop down menu choice | ksigcajun | Word VBA | 6 | 06-10-2014 09:39 AM |
Maximum Number Of Styles-Based-On? | Pluviophile | Word | 13 | 05-08-2014 05:29 AM |
finding data from different tables based on header | s7y | Excel | 3 | 11-11-2013 09:09 AM |