+ Reply to Thread
Results 1 to 7 of 7

VBA to save word doc into individual pages and name according to first line on each page

  1. #1
    Registered User
    Join Date
    04-18-2017
    Location
    London
    MS-Off Ver
    2010
    Posts
    5

    VBA to save word doc into individual pages and name according to first line on each page

    Hello,

    I need a VBA code to save a large word file into individual pages and for it to rename each doc according to the first line on the page. I've found the two codes below, which seem to do part of what I need, but can't figure out how to merge the two.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Thanks!
    Last edited by alansidman; 06-05-2018 at 09:50 AM.

  2. #2
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: VBA to save word doc into individual pages and name according to first line on each pa

    Such documents are usually the result of a mailmerge. If that's so in this case, see Split Merged Output to Separate Documents in the Mailmerge Tips and Tricks thread at:
    http://www.msofficeforums.com/mail-m...ps-tricks.html
    or:
    http://windowssecrets.com/forums/sho...ips-amp-Tricks
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Registered User
    Join Date
    04-18-2017
    Location
    London
    MS-Off Ver
    2010
    Posts
    5

    Re: VBA to save word doc into individual pages and name according to first line on each pa

    Thanks for the response.
    Unfortunately, I don't think the threads mentioned are applicable as my word doc is not linked to a mail merge.
    Any other suggestions?
    Thanks

  4. #4
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: VBA to save word doc into individual pages and name according to first line on each pa

    Regardless, the solution depends on what separates your pages. If they're separated by Section breaks, the macro in either of the links will serve as the basis for the splitting. If they're separated by manual page breaks, a different (though not too difficult) approach can be applied; otherwise, things are a whole lot more complicated because what Word thinks constitutes a page depends on how it optimizes the document's layout to suit the active printer.

  5. #5
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,882

    Re: VBA to save word doc into individual pages and name according to first line on each pa

    Code Tags Added
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  6. #6
    Registered User
    Join Date
    04-18-2017
    Location
    London
    MS-Off Ver
    2010
    Posts
    5

    Re: VBA to save word doc into individual pages and name according to first line on each pa

    Thanks for clarifying. Your code Sub SplitMergedDocument() seems to work. However, my doc doesn't seem to be split by section breaks throughout, so it's giving me docs with 3-5 pages each time. Is there a way to fix this?

  7. #7
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: VBA to save word doc into individual pages and name according to first line on each pa

    If your document isn't split in a consistent manner, that makes it unnecessarily difficult to process with a macro. I'd suggest inserting Section breaks where required (Find/Replace can be used to replace manual page breaks, if your document has them, with Section breaks), then running the macro.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA Excel to Word Printing individual pages in range
    By Slugger65 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-10-2015, 01:07 AM
  2. Post Excel Rows to Individual Word Docs and Save as new file
    By Mad-Dog in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-01-2014, 06:18 AM
  3. Replies: 0
    Last Post: 07-30-2014, 11:25 AM
  4. Replies: 3
    Last Post: 12-06-2013, 01:25 AM
  5. [SOLVED] VBA to enter the page of pages and then the date on the second line of the footer
    By bstier in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-10-2013, 11:36 PM
  6. [SOLVED] Save selected pages to desktop without running each page code?
    By matrixpom in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-10-2012, 11:56 PM
  7. Extract pages from word file and save extracted pages to new word file
    By bonny24tycoon in forum Word Programming / VBA / Macros
    Replies: 3
    Last Post: 06-28-2012, 09:45 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1