Hi Word-Gods!

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 identify it as belonging to a section, 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? I can't work this out and I need it for work

Any help would be greatly appreciated. x




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