Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Star Lounger
    Join Date
    Aug 2002
    Location
    Orlando, Florida, USA
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macro to copy table to another page (Word XP)

    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.
    Attached Files Attached Files

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Macro to copy table to another page (Word XP)

    You can simulate a copy and paste action of the first table in a document with this code:

    <pre>Sub PasteFirstTableToEndOfDocument()
    ActiveDocument.Tables(1).Select
    With Selection
    .Copy
    .EndKey Unit:=wdStory, Extend:=wdMove
    .TypeParagraph
    .Paste
    End With
    End Sub</pre>

    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:

    <pre>Sub PasteFirstTableToEndOfDocument()
    With Selection
    .EndKey Unit:=wdStory, Extend:=wdMove
    .TypeParagraph
    End With
    NormalTemplate.AutoTextEntries("_TESTONLY").Insert _
    Where:=Selection.Range, RichText:=True
    End Sub</pre>

    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.

  3. #3
    Star Lounger
    Join Date
    Aug 2002
    Location
    Orlando, Florida, USA
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro to copy table to another page (Word XP)

    Okay, I have attached it again becuase it is not working, I added it as an autotext and put the name of the autotext inside the code and when I get to the bottom of the form it retuns me to the top.
    Attached Files Attached Files

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Macro to copy table to another page (Word XP)

    Hee hee. I downloaded it to test and guess what: no AutoText. This is that portability problem I mentioned...

    Okay, so, when you say the code returns you to the top, do you mean it does not insert anything and returns to the beginning of the document?

  5. #5
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Macro to copy table to another page (Word XP)

    LL,

    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

  6. #6
    Star Lounger
    Join Date
    Aug 2002
    Location
    Orlando, Florida, USA
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro to copy table to another page (Word XP)

    Yes 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.

  7. #7
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Macro to copy table to another page (Word XP)

    Hmm, 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

  8. #8
    Star Lounger
    Join Date
    Aug 2002
    Location
    Orlando, Florida, USA
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro to copy table to another page (Word XP)

    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?
    <img src=/S/butterfly.gif border=0 alt=butterfly width=15 height=15> 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?

    <img src=/S/butterfly.gif border=0 alt=butterfly width=15 height=15> 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.

  9. #9
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Macro to copy table to another page (Word XP)

    Hi 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
    Attached Files Attached Files

  10. #10
    Star Lounger
    Join Date
    Aug 2002
    Location
    Orlando, Florida, USA
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro to copy table to another page (Word XP)

    Thank you. I will give it a try and let you know what happens.

  11. #11
    Star Lounger
    Join Date
    Aug 2002
    Location
    Orlando, Florida, USA
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro to copy table to another page (Word XP)

    I 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.

  12. #12
    Star Lounger
    Join Date
    Mar 2001
    Location
    St Georges du Bois, Pays de la Loire
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro to copy table to another page (Word XP)

    I 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 Integer


    pass = "your password here"

    i = ActiveDocument.Tables.count

    table_num = i

    ActiveDocument.Unprotect Password:=(pass)

    With ActiveDocument.Tables(table_num)
    .Select
    End With

    Selection.copy

    Selection.EndKey Unit:=wdStory

    Selection.InsertBreak Type:=wdPageBreak
    Selection.Paste

    i = ActiveDocument.Tables.count

    table_num = i

    With ActiveDocument.Tables(table_num)
    .Select
    Selection.Fields.Update
    End With

    ActiveDocument.Protect Password:=(pass), NoReset:=True, Type:=wdAllowOnlyFormFields


    End Sub

  13. #13
    Star Lounger
    Join Date
    Aug 2002
    Location
    Orlando, Florida, USA
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro to copy table to another page (Word XP)

    Thank you I will try this to.

  14. #14
    Star Lounger
    Join Date
    Aug 2002
    Location
    Orlando, Florida, USA
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro to copy table to another page (Word XP)

    IT WORKS... THANK YOU SO MUCH!!!! <img src=/S/bananas.gif border=0 alt=bananas width=33 height=35> <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23> <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

  15. #15
    Star Lounger
    Join Date
    Mar 2001
    Location
    St Georges du Bois, Pays de la Loire
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro to copy table to another page (Word XP)

    Well, I am pleased. I retire in September to France to run a B&B and to restore the old cottage next door... I cannot often contribute but I have had so much help from the Forum over the last few years.

    Glad to have been of help.

    David

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •