I would like to know how to build a macro to get the attached table to copy if the user needs to create a second, third, fourth … etc page.
![]() |
There are isolated problems with current patches, but they are well-known and documented on this site. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Macro to copy table to another page (Word XP)
Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Macro to copy table to another page (Word XP)
- This topic has 17 replies, 5 voices, and was last updated 18 years, 7 months ago.
AuthorTopicWSLizardLips
AskWoody LoungerJune 13, 2003 at 6:43 pm #389033Viewing 0 reply threadsAuthorReplies-
WSjscher2000
AskWoody LoungerJune 13, 2003 at 7:01 pm #685603You can simulate a copy and paste action of the first table in a document with this code:
Sub PasteFirstTableToEndOfDocument() ActiveDocument.Tables(1).Select With Selection .Copy .EndKey Unit:=wdStory, Extend:=wdMove .TypeParagraph .Paste End With End Sub
On the other hand, if you need the table to be “clean” rather than filled in, you might want to save it as AutoText and use the Insert method:
Sub PasteFirstTableToEndOfDocument() With Selection .EndKey Unit:=wdStory, Extend:=wdMove .TypeParagraph End With NormalTemplate.AutoTextEntries("_TESTONLY").Insert _ Where:=Selection.Range, RichText:=True End Sub
The trick here is where to store the AutoText entry. Since AutoText can be stored only in a template and not in a document, you have a few choices: the NormalTemplate, the ActiveDocument.AttachedTemplate, or a global template. Each has pros and cons, but all suffer from a lack of “portability” in that once the document moves to a machine without an appropriate template, the macro will fail. Maybe you can have the macro first try AutoText and, if it doesn’t find it, copy the first table. Whatever is most practical for your needs. Hope this helps.
-
WSLizardLips
AskWoody Lounger -
WSjscher2000
AskWoody Lounger -
WSGary Frieder
AskWoody LoungerJune 16, 2003 at 3:02 am #685938LL,
The sample document you attached is full of formfields (although when I open the document it is not currently protected for forms). Are you by any chance trying to do this table copy routine while the document is protected for forms? – if so, then more code needs to added to the routine: to first unprotect the document, then do the table copy/paste or autotext insert bit, and finally to reprotect the document with NoReset = True.
Gary
-
WSLizardLips
AskWoody LoungerJune 16, 2003 at 12:44 pm #686004Yes it will be a protected form template, I tried to attach the protected template but was not able to I had to change it to a .doc in order to attach it. But yes it will a template that I need to put out to my users and as they are typing in it when they get to the bottom I need it to create that table onto the next page.
-
WSGary Frieder
AskWoody LoungerJune 16, 2003 at 4:59 pm #686058Hmm, that would be really tricky to do, if possible at all. There’s no built-in way to do that either in Word directly or using Word VBA.
Can you clarify what you need the content on the next page to contain – do you want the entire table to repeat, including the heading row with ‘Client Name’, ‘Matter Name’ etc., or do you just want additional sequentially numbered entry rows to be added?
Also, it’s not necessarily going to be a user adding an entry into the last row currently available (#8) that could force your page 1 table to extend onto another page – for example if the user adds a long entry into row #1, that is going to be force row #8 over onto page 2. You can help things there somewhat by defining the table rows to be an ‘exact’, rather than ‘at least’ height – the tradeoff there though is that if the user has a long entry to make, they will not be able to get it to fit into the cell.
But the real hurdle would be getting Word to respond automatically and add another table, when the user got to the end of entry #8 – do you require the adding of the additional content to be automatic, or would it be OK to require the user to press a button on a custom toolbar, in order to add more rows?
The former would be really hard to do, but the latter might be feasible – per my previous post, you would then just need code to unprotect the document, go to the end of the document, insert an autotext, and reprotect the document without losing the formfield content.Hope the above makes sense; if possible post back with more clarification per the above questions.
Gary
-
WSLizardLips
AskWoody LoungerJune 18, 2003 at 2:13 pm #686676Can you clarify what you need the content on the next page to contain – do you want the entire table to repeat, including the heading row with ‘Client Name’, ‘Matter Name’ etc., or do you just want additional sequentially numbered entry rows to be added?
Sequentially numbered entry rows would be fine, but if it is easier to dothe whole table then table with ‘client name’, matter name etc that would be fine to.
But the real hurdle would be getting Word to respond automatically and add another table, when the user got to the end of entry #8 – do you require the adding of the additional content to be automatic, or would it be OK to require the user to press a button on a custom toolbar, in order to add more rows?
I would want the table to start over after the person got to entry 8, then they can either push a button on the tool bar, run a macro or tab and a new table would be created.
Let me know what you think. -
WSGary Frieder
AskWoody LoungerJune 19, 2003 at 3:14 am #686861Hi again,
Here’s a revised version of your template – this has got an autotext and code to add one new row at a time – you would need to add a custom toolbar and a button linked to the ‘AddAnotherRow’ procedure.
I had trouble controlling your table until I changed the Text Wrapping from ‘Around’ to ‘None’ – with it set to Around, the table behaves like a floating graphic object and becomes very difficult to control.
Give this a try and see if it does what you need it to do…..
Gary
-
WSLizardLips
AskWoody Lounger -
WSLizardLips
AskWoody LoungerJune 23, 2003 at 4:19 pm #687856I downloaded and unziped your attachment and I copied it to where my templates live and I tried it and I still cannot get it to work. When I get to the bottom it takes me back up to the top and in looking at it I was also thinking that the headers don’t need to repeat that I would just need the table to continue on with number 8 and down then line. Let me know what you think.
-
WSsolomod
AskWoody LoungerJune 25, 2003 at 12:49 pm #688566I use this macro on my forms – it unprotects the doc, finds the last table, copies it, adds a page and pastes the table on, then clears the table entries. I activate the macro from a command button on the first page.
Sub add_page()
Dim pass
Dim table_num As Integer
Dim i As Integerpass = “your password here”
i = ActiveDocument.Tables.count
table_num = i
ActiveDocument.Unprotect Password:=(pass)
With ActiveDocument.Tables(table_num)
.Select
End WithSelection.copy
Selection.EndKey Unit:=wdStory
Selection.InsertBreak Type:=wdPageBreak
Selection.Pastei = ActiveDocument.Tables.count
table_num = i
With ActiveDocument.Tables(table_num)
.Select
Selection.Fields.Update
End WithActiveDocument.Protect Password:=(pass), NoReset:=True, Type:=wdAllowOnlyFormFields
End Sub
-
WSLizardLips
AskWoody Lounger -
WSLizardLips
AskWoody Lounger -
WSsolomod
AskWoody Lounger -
WSLizardLips
AskWoody Lounger -
WSGary Frieder
AskWoody LoungerJune 29, 2003 at 1:13 am #689912Hi LL,
Apologies for not getting back to you sooner – was away from the Lounge for a few days.
Not sure why the macro didn’t work for you – what it does is unprotect the document, add another row (with autonumber), and then reprotects the document. The reason it takes you back to the top is because reprotecting the document automatically takes you back to the top. The macro doesn’t add a header, just the individual row.
Anyway I’m glad to see that David has come up with solution that you could use!
Gary
-
-
-
-
-
WSSME
AskWoody Lounger
Viewing 0 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Windows AI Local Only no NPU required!
by
RetiredGeek
37 seconds ago -
Stop the OneDrive defaults
by
CWBillow
3 hours, 3 minutes ago -
Windows 11 Insider Preview build 27868 released to Canary
by
joep517
5 hours, 28 minutes ago -
X Suspends Encrypted DMs
by
Alex5723
7 hours, 40 minutes ago -
WSJ : My Robot and Me AI generated movie
by
Alex5723
7 hours, 58 minutes ago -
Botnet hacks 9,000+ ASUS routers to add persistent SSH backdoor
by
Alex5723
8 hours, 35 minutes ago -
OpenAI model sabotages shutdown code
by
Cybertooth
9 hours, 12 minutes ago -
Backup and access old e-mails after company e-mail address is terminated
by
M W Leijendekker
4 hours, 30 minutes ago -
Enabling Secureboot
by
ITguy
4 hours, 22 minutes ago -
Windows hosting exposes additional bugs
by
Susan Bradley
17 hours, 7 minutes ago -
No more rounded corners??
by
CWBillow
12 hours, 55 minutes ago -
Android 15 and IPV6
by
Win7and10
2 hours, 40 minutes ago -
KB5058405 might fail to install with recovery error 0xc0000098 in ACPI.sys
by
Susan Bradley
1 day, 5 hours ago -
T-Mobile’s T-Life App has a “Screen Recording Tool” Turned on
by
Alex5723
1 day, 8 hours ago -
Windows 11 Insider Preview Build 26100.4202 (24H2) released to Release Preview
by
joep517
1 day, 2 hours ago -
Windows Update orchestration platform to update all software
by
Alex5723
1 day, 15 hours ago -
May preview updates
by
Susan Bradley
1 day, 2 hours ago -
Microsoft releases KB5061977 Windows 11 24H2, Server 2025 emergency out of band
by
Alex5723
18 hours, 27 minutes ago -
Just got this pop-up page while browsing
by
Alex5723
1 day, 7 hours ago -
KB5058379 / KB 5061768 Failures
by
crown
1 day, 4 hours ago -
Windows 10 23H2 Good to Update to ?
by
jkitc
6 hours, 55 minutes ago -
At last – installation of 24H2
by
Botswana12
2 days, 7 hours ago -
MS-DEFCON 4: As good as it gets
by
Susan Bradley
3 hours, 42 minutes ago -
RyTuneX optimize Windows 10/11 tool
by
Alex5723
2 days, 19 hours ago -
Can I just update from Win11 22H2 to 23H2?
by
Dave Easley
17 hours, 38 minutes ago -
Limited account permission error related to Windows Update
by
gtd12345
3 days, 8 hours ago -
Another test post
by
gtd12345
3 days, 8 hours ago -
Connect to someone else computer
by
wadeer
3 days, 3 hours ago -
Limit on User names?
by
CWBillow
3 days, 6 hours ago -
Choose the right apps for traveling
by
Peter Deegan
2 days, 20 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.