Results 1 to 7 of 7
  1. #1
    New Lounger
    Join Date
    Dec 2013
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Word Macro to add line to table and copy template for each line

    Template.doc i Have a basic word document with a table in made up of three columns. Column 1 is called "Task No", Column 2 is called "Description of works" and Column 3 is called "Works location". I also have a two page template for photos to be inserted into. What i would like to be able to do is fill out the above criteria and click a button at the bottom of the table to add a new line of date, also once a new line is added then the two template pages are duplicated...?? Everytime you add a new line then another set of pages will be added. Can anyone please advise as to the best way in doing this?

    Thanks in advance for any advice.
    Last edited by carllewisElephant; 2013-12-03 at 16:30.

  2. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    With a Word table, simply tabbing out of the last cell will add a new row - with the same format as the current one. Word has no facility for automatically adding more pages to the document, though. For that, you'd need a macro. One way would be to have an ActiveX button at the top of the table that the user can click on to add pages. Another way would be to use a WindowSelectionChange macro attached to the document's template. Such a macro can be made to fire anytime the user creates a new row. If you use Word's 'Normal' template for this latter approach, though, it could have adverse effects on other documents, adding extra pages to them when you don't really want to do so.

    Beyond that, your document would require some re-working to make it more suitable for this kind of process. For example, your extra pages have lots of empty paragraphs below the textboxes for pushing the next table down to the following page; you should use manual page breaks (or Next page Section breaks) instead. Similarly, you'd probably do better to not have the textboxes for the pictures and, instead, add another row to each table. By fixing the height and width of that row, you can force any inserted pictures to fit within the space allowed, something you can't do with textboxes.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  3. #3
    New Lounger
    Join Date
    Dec 2013
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Hi Paul, thanks for commenting and sorry for the delay in responding. If i was to you the ActiveX button option which sounds the easiest is there a command command or script that can be used?

  4. #4
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    See attached updated version of your document. Note that I've modified the layout along the lines suggested above. The code is attached to the ActiveX button.
    Attached Files Attached Files
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  5. #5
    New Lounger
    Join Date
    Dec 2013
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts

    New Template

    Hi Paul, i have uploaded my full template with the button on page 6, the pages i would like to copy and paste when the button is pressed are 15-17 would this be possible?
    Attached Files Attached Files

  6. #6
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    It's of no consequence what page the button to initiate the replication is located on.

    However, whilst replicating pages with the document in your initial post, which had a simple page layout for which the implication was that you wanted two copies was easy enough, replicating the considerably more complicated structure you have in your latest version would be considerably more difficult.

    All that was needed for the original was some code to copy a page range, paste & delete all contents.

    What you're after now appears to span a Section break with different page orientations, a variety of textboxes with embedded tables etc, none of which I have any idea as to what is to be retained, modified or deleted, spanning 4 pages before the last page and to insert that range, where - before page 18, or after it?

    To handle such complexity, what you really need is a separate document/template containing just the pages to be replicated, so you could use, perhaps, the InsertFile method to insert copies of the source document as & when required.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  7. The Following User Says Thank You to macropod For This Useful Post:

    carllewisElephant (2013-12-05)

  8. #7
    New Lounger
    Join Date
    Dec 2013
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks Paul!!

Tags for this Thread

Posting Permissions

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