Results 1 to 7 of 7
  1. #1
    New Lounger
    Join Date
    Sep 2016
    Posts
    13
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Code to extract individual pages as separate files

    Hi folks,

    A client has given us Word documents, each 100-200 pages long, containing combined narratives for individual subjects in a clinical trial. They've asked us to edit the narratives and deliver back to them each narrative as an individual Word file.

    Each narrative is defined by a page break so I'm thinking this could be automated (select all the text between this page break and the next, copy, paste into new document, repeat) but I'm not smart enough to write the code (and maybe I'm totally on the wrong track). Anyone willing and able to help me out?

    Thanks in advance for any assistance you can offer.

    Beej

  2. #2
    Super Moderator macropod's Avatar
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,216
    Thanks
    2
    Thanked 465 Times in 382 Posts
    A quick & dirty way would be to use Find/Replace to replace the page breaks with Section breaks, then use the macro under Split Merged Output to Separate Documents in the Mailmerge Tips and Tricks thread (https://windowssecrets.com/forums/sho...ips-amp-Tricks) to split the file.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

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

    Beej@impact (2017-03-09)

  4. #3
    WS Lounge VIP mrjimphelps's Avatar
    Join Date
    Dec 2009
    Location
    USA
    Posts
    3,920
    Thanks
    506
    Thanked 455 Times in 424 Posts
    If you're going to edit the entire document anyway, it would be a lot simpler, and you would get exactly the results you want, if you do the following for each Word document:

    Open the Word document.
    Do the following for each narrative in the document:
    * Open a new, blank Word document.
    * Select (highlight) an entire narrative, then choose Cut.
    * Paste the narrative into the new, blank Word document.
    * Save the new document with an appropriate name.
    * Edit the narrative as needed.
    * Save the original document.
    * Save and close the new document.

    (Be sure to make copies of all of the original Word documents before starting.)

    In my opinion, if you try to automate something like that, you may get results that you aren't expecting. For example, what if there are additional page breaks in the document besides the one after each narrative?

    You may spend as much time trying to get the automation to work correctly as you would spend simply doing the whole thing as I have described above.

    Once you have done a few, the process will go quickly.
    Last edited by mrjimphelps; 2017-03-10 at 14:57.

  5. #4
    3 Star Lounger
    Join Date
    May 2010
    Location
    Philadelphia, PA, USA
    Posts
    216
    Thanks
    3
    Thanked 29 Times in 27 Posts
    Quote Originally Posted by mrjimphelps View Post
    If you're going to edit the entire document anyway, it would be a lot simpler, and you would get exactly the results you want, if you do the following for each Word document:

    Open the Word document.
    Do the following for each narrative in the document:
    * Open a new, blank Word document.
    * Select (highlight) an entire narrative, then choose Cut.
    * Paste the narrative into the new, blank Word document.
    * Save the new document with an appropriate name.
    * Edit the narrative as needed.
    * Save the original document.
    * Save and close the new document.

    (Be sure to make copies of all of the original Word documents before starting.)

    In my opinion, if you try to automate something like that, you may get results that you aren't expecting. For example, what if there are additional page breaks in the document besides the one after each narrative?

    You may spend as much time trying to get the automation to work correctly as you would spend simply doing the whole thing as I have described above.

    Once you have done a few, the process will go quickly.
    The next to last sentence is so true. I can't remember how many times I tried to use a macro to do something and spent MORE time than if I had done it manually.

  6. #5
    Super Moderator macropod's Avatar
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,216
    Thanks
    2
    Thanked 465 Times in 382 Posts
    In this case, though, all the hard work has already been done.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  7. #6
    WS Lounge VIP mrjimphelps's Avatar
    Join Date
    Dec 2009
    Location
    USA
    Posts
    3,920
    Thanks
    506
    Thanked 455 Times in 424 Posts
    Quote Originally Posted by macropod View Post
    In this case, though, all the hard work has already been done.
    IF the documents are exactly as he hopes that they are.

  8. #7
    Super Moderator macropod's Avatar
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,216
    Thanks
    2
    Thanked 465 Times in 382 Posts
    Quote Originally Posted by mrjimphelps View Post
    IF the documents are exactly as he hopes that they are.
    Hardly an issue in this case. The output specs are quite clear: one new document per manual page break in the source files.

    So how about we wait until the OP actually says the solution I suggested doesn't work instead of continuing this rather pointless speculation???
    Cheers,

    Paul Edstein
    [MS MVP - Word]

Posting Permissions

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