• Code to extract individual pages as separate files

    Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Code to extract individual pages as separate files

    Author
    Topic
    #508361

    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

    Viewing 2 reply threads
    Author
    Replies
    • #1593081

      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 (http://windowssecrets.com/forums/showthread//163017-Word-Mailmerge-Tips-amp-Tricks) to split the file.

      Cheers,
      Paul Edstein
      [Fmr MS MVP - Word]

    • #1593232

      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.

      Group "L" (Linux Mint)
      with Windows 10 running in a remote session on my file server
      • #1593516

        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.

    • #1593532

      In this case, though, all the hard work has already been done.

      Cheers,
      Paul Edstein
      [Fmr MS MVP - Word]

      • #1593853

        In this case, though, all the hard work has already been done.

        IF the documents are exactly as he hopes that they are.

        Group "L" (Linux Mint)
        with Windows 10 running in a remote session on my file server
        • #1593879

          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
          [Fmr MS MVP - Word]

    Viewing 2 reply threads
    Reply To: Code to extract individual pages as separate files

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: