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, 5 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
-
TotalAV safety warning popup
by
Theodore Nicholson
40 minutes ago -
two pages side by side land scape
by
marc
19 hours, 53 minutes ago -
Deleting obsolete OneNote notebooks
by
afillat
21 hours, 59 minutes ago -
Word/Outlook 2024 vs Dragon Professional 16
by
Kathy Stevens
50 minutes ago -
Security Essentials or Defender?
by
MalcolmP
3 hours, 35 minutes ago -
April 2025 updates out
by
Susan Bradley
7 minutes ago -
Framework to stop selling some PCs in the US due to new tariffs
by
Alex5723
10 hours, 19 minutes ago -
WARNING about Nvidia driver version 572.83 and 4000/5000 series cards
by
Bob99
4 hours, 3 minutes ago -
Creating an Index in Word 365
by
CWBillow
13 hours, 32 minutes ago -
Coming at Word 365 and Table of Contents
by
CWBillow
5 hours, 1 minute ago -
Windows 11 Insider Preview Build 22635.5170 (23H2) released to BETA
by
joep517
1 day, 16 hours ago -
Has the Microsoft Account Sharing Problem Been Fixed?
by
jknauth
1 day, 20 hours ago -
W11 24H2 – Susan Bradley
by
G Pickerell
1 day, 22 hours ago -
7 tips to get the most out of Windows 11
by
Alex5723
1 day, 20 hours ago -
Using Office apps with non-Microsoft cloud services
by
Peter Deegan
1 day, 13 hours ago -
I installed Windows 11 24H2
by
Will Fastie
5 hours, 11 minutes ago -
NotifyIcons — Put that System tray to work!
by
Deanna McElveen
2 days, 1 hour ago -
Decisions to be made before moving to Windows 11
by
Susan Bradley
4 minutes ago -
Port of Seattle says ransomware breach impacts 90,000 people
by
Nibbled To Death By Ducks
2 days, 9 hours ago -
Looking for personal finance software with budgeting capabilities
by
cellsee6
1 day, 18 hours ago -
ATT/Yahoo Secure Mail Key
by
Lil88reb
1 day, 18 hours ago -
Devices with apps using sprotect.sys driver might stop responding
by
Alex5723
3 days, 3 hours ago -
Neowin – 20 times computers embarrassed themselves with public BSODs and goofups
by
EP
3 days, 11 hours ago -
Slow Down in Windows 10 performance after March 2025 updates ??
by
arbrich
2 days, 13 hours ago -
Mail from certain domains not delivered to my outlook.com address
by
pumphouse
2 days, 19 hours ago -
Is data that is in OneDrive also taking up space on my computer?
by
WShollis1818
3 days, 6 hours ago -
Nvidia just fixed an AMD Linux bug
by
Alex5723
4 days, 22 hours ago -
50 years and counting
by
Susan Bradley
1 day, 20 hours ago -
Fix Bluetooth Device Failed to Delete in Windows Settings
by
Drcard:))
1 day, 23 hours ago -
Licensing and pricing updates for on-premises server products coming July 2025
by
Alex5723
5 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.