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.
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
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, 6 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
-
Login screen icon
by
CWBillow
1 hour, 14 minutes ago -
AI coming to everything
by
Susan Bradley
2 hours, 50 minutes ago -
Mozilla : Pocket shuts down July 8, 2025, Fakespot shuts down on July 1, 2025
by
Alex5723
5 hours, 1 minute ago -
No Screen TurnOff???
by
CWBillow
5 hours, 23 minutes ago -
Identify a dynamic range to then be used in another formula
by
BigDaddy07
5 hours, 56 minutes ago -
InfoStealer Malware Data Breach Exposed 184 Million Logins and Passwords
by
Alex5723
17 hours, 32 minutes ago -
How well does your browser block trackers?
by
n0ads
3 hours, 50 minutes ago -
You can’t handle me
by
Susan Bradley
8 hours, 15 minutes ago -
Chrome Can Now Change Your Weak Passwords for You
by
Alex5723
3 hours, 18 minutes ago -
Microsoft: Over 394,000 Windows PCs infected by Lumma malware, affects Chrome..
by
Alex5723
1 day, 4 hours ago -
Signal vs Microsoft’s Recall ; By Default, Signal Doesn’t Recall
by
Alex5723
8 hours, 25 minutes ago -
Internet Archive : This is where all of The Internet is stored
by
Alex5723
1 day, 5 hours ago -
iPhone 7 Plus and the iPhone 8 on Vantage list
by
Alex5723
1 day, 5 hours ago -
Lumma malware takedown
by
EyesOnWindows
17 hours, 39 minutes ago -
“kill switches” found in Chinese made power inverters
by
Alex5723
1 day, 14 hours ago -
Windows 11 – InControl vs pausing Windows updates
by
Kathy Stevens
1 day, 14 hours ago -
Meet Gemini in Chrome
by
Alex5723
1 day, 18 hours ago -
DuckDuckGo’s Duck.ai added GPT-4o mini
by
Alex5723
1 day, 18 hours ago -
Trump signs Take It Down Act
by
Alex5723
2 days, 2 hours ago -
Do you have a maintenance window?
by
Susan Bradley
6 hours, 59 minutes ago -
Freshly discovered bug in OpenPGP.js undermines whole point of encrypted comms
by
Nibbled To Death By Ducks
1 day, 4 hours ago -
Cox Communications and Charter Communications to merge
by
not so anon
2 days, 5 hours ago -
Help with WD usb driver on Windows 11
by
Tex265
14 hours ago -
hibernate activation
by
e_belmont
2 days, 14 hours ago -
Red Hat Enterprise Linux 10 with AI assistant
by
Alex5723
2 days, 18 hours ago -
Windows 11 Insider Preview build 26200.5603 released to DEV
by
joep517
2 days, 21 hours ago -
Windows 11 Insider Preview build 26120.4151 (24H2) released to BETA
by
joep517
2 days, 21 hours ago -
Fixing Windows 24H2 failed KB5058411 install
by
Alex5723
1 day, 17 hours ago -
Out of band for Windows 10
by
Susan Bradley
3 days, 2 hours ago -
Giving UniGetUi a test run.
by
RetiredGeek
3 days, 9 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.