1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

How to split a Word document into multiple documents?

Discussion in 'Business Applications' started by michelle_s, Jan 29, 2011.

Thread Status:
Not open for further replies.
Advertisement
  1. michelle_s

    michelle_s Thread Starter

    Joined:
    Jan 28, 2011
    Messages:
    15
    Hi there!

    I've got a word document that I need to split into new documents. Each page has a specific value on it that I could use to copy the pages that have this value on them into a new workbook. i.e. the first 5 pages of the workbook might have the value 2468 on it. the next 3 pages might have the value 3579 on them, the subsequent 8 pages might have the value 6789 on them.

    Can anyone show me how to do this in VBA? I was thinking that I could maybe:

    1) find the last page that the values appear on
    2) add a page break
    3) copy the pages of the book into new documents based on locations of page breaks I've added.

    But I don't know how to do that, especially the bits with question marks...

    Can anyone help me out?

    :)


    Public Sub CreatePageBreaks_and SplitDoc()

    Dim Mydoc As Document, NewDoc As Document
    Set MyDoc = Word.Documents("C:\myfolder\mydoc.doc")
    Selection.HomeKey Unit:=wdStory

    MyConst = 2468

    'get page that value last appears on
    Dim y1 As Integer
    Dim r1 As Word.Range
    Set r1 = MyDoc.Content
    If r1.Find.Execute(FindText:=MyConst, Forward:=False, Wrap:=False) = True Then
    y1 = r1.Information(wdActiveEndPageNumber)
    End If

    'create page breaks based on page that last value is on?????

    NewDocName = "c:\myfolder\mydoc_ " & MyConst

    'copy pages up until/between page break and copy into a new doc?????

    NewDoc.SaveAs filename:=NewDocName
    NewDoc.Close
    MyDoc.Close wdDoNotSaveChanges

    End Sub
     
  2. michelle_s

    michelle_s Thread Starter

    Joined:
    Jan 28, 2011
    Messages:
    15
    Hi Rollin_Again,

    Hope you don't mind me asking you directly, but I've read your response to a similar query about splitting a word document. Do you think your code can be adapted for my purposes??

    Any help would be really appreciated! :)

    xxxxxxx


     
  3. Rollin_Again

    Rollin_Again

    Joined:
    Sep 4, 2003
    Messages:
    4,912
    Please post a sample document.

    Rollin
     
  4. michelle_s

    michelle_s Thread Starter

    Joined:
    Jan 28, 2011
    Messages:
    15
    Hi Rollin,

    So many thanks for having a look. :)

    I've attached a sample document. It included quite a lot of sensitive data so you'll have to excuse all the x's and y's. I've also only included a few pages from the document but you'll notice that the footer references the document as being 113 pages long.

    The value that I think can be used to group the pages are in the top left. They're in frames, but I can just loop through the doc to delete the frames out with another macro if needs be. It would be great if I can keep the formatting as it is too.

    Again, so grateful for you offering to have a look. Really kind of you.

    Thanks,

    Michelle.
     

    Attached Files:

  5. Rollin_Again

    Rollin_Again

    Joined:
    Sep 4, 2003
    Messages:
    4,912
    Page 1 in your sample contained the header Conflicts Report is this a generic 1st page cover that can be skipped or will something need to be done with it? I assume each separate document will be seperated by the section headers? (e.g - 4480 Section1, 2050 Section2, etc.)

    Rollin
     
  6. michelle_s

    michelle_s Thread Starter

    Joined:
    Jan 28, 2011
    Messages:
    15
    Hi Rollin,

    Yes, that can be skipped, it doesn't need to be included in each section. You're correct in your assumption that it would be separated by the section headers, 4480, 2050 and so on.

    Thanks. :)
     
  7. michelle_s

    michelle_s Thread Starter

    Joined:
    Jan 28, 2011
    Messages:
    15
    Hi Rollin,

    I was just wondering if you'd had any ideas about this? No problems if not (not trying to pressure you!) - I was just wondering if it's actually possible to do at all? :)

    Thanks so much,

    Michelle.
     
  8. Rollin_Again

    Rollin_Again

    Joined:
    Sep 4, 2003
    Messages:
    4,912
    Yes it's possible to do but I just haven't had a chance to look at it yet. I'll take a look later today and post back.

    Rollin
     
  9. michelle_s

    michelle_s Thread Starter

    Joined:
    Jan 28, 2011
    Messages:
    15
    That's great thanks. Just whenever you have time. :)
     
  10. michelle_s

    michelle_s Thread Starter

    Joined:
    Jan 28, 2011
    Messages:
    15
    Hi Rollin,

    Just to let you know that I think I've managed to fix this with someone's help.

    Thanks for your offer to help though, it was really kind of you. :)
     
  11. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/977647

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice