Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-25-2015, 06:43 AM
coba coba is offline adding tables based on a number given in a form Mac OS X adding tables based on a number given in a form Office for Mac 2011
Novice
adding tables based on a number given in a form
 
Join Date: Dec 2015
Posts: 7
coba is on a distinguished road
Default 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
Attached Files
File Type: docx QuestionForum.docx (42.0 KB, 10 views)
Reply With Quote
  #2  
Old 12-25-2015, 07:29 AM
gmaxey gmaxey is offline adding tables based on a number given in a form Windows 7 32bit adding tables based on a number given in a form Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,598
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

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
Attached Files
File Type: dotm QuestionForum.dotm (25.9 KB, 18 views)
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 12-25-2015, 07:44 AM
coba coba is offline adding tables based on a number given in a form Mac OS X adding tables based on a number given in a form Office for Mac 2011
Novice
adding tables based on a number given in a form
 
Join Date: Dec 2015
Posts: 7
coba is on a distinguished road
Default

Thank you so much, Greg, for your help.
Reply With Quote
  #4  
Old 12-26-2015, 08:43 AM
coba coba is offline adding tables based on a number given in a form Mac OS X adding tables based on a number given in a form Office for Mac 2011
Novice
adding tables based on a number given in a form
 
Join Date: Dec 2015
Posts: 7
coba is on a distinguished road
Default

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.
Reply With Quote
  #5  
Old 12-26-2015, 02:56 PM
coba coba is offline adding tables based on a number given in a form Mac OS X adding tables based on a number given in a form Office for Mac 2011
Novice
adding tables based on a number given in a form
 
Join Date: Dec 2015
Posts: 7
coba is on a distinguished road
Default

The problem is solved
Reply With Quote
  #6  
Old 12-26-2015, 07:05 PM
gmaxey gmaxey is offline adding tables based on a number given in a form Windows 7 32bit adding tables based on a number given in a form Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,598
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

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.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply

Tags
form field, table, word vba.



Similar Threads
Thread Thread Starter Forum Replies Last Post
adding tables based on a number given in a form 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 tables based on a number given in a form 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

Other Forums: Access Forums

All times are GMT -7. The time now is 03:40 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft