For Programmers: Free Programming Magazines  


Home > Archive > MSDN > June 2004 > separate word document by hard pagebreaks









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author separate word document by hard pagebreaks
Eric

2004-06-01, 2:31 am


How can I separate a large word document by hard pagebreaks into separate files? Here is what I have, ... but doesn't seem to work correctly:

Dim i As Integer
Dim iNumPages As Integer
Dim sCurrentDoc As String

sCurrentDoc = ActiveDocument.Name
'Get the current document's name
iNumPages = 1
'Get the number of docs
For i = 1 To iNumPages
'For as many times as there are docs

Selection.GoTo What:=wdGoToPage, which:=wdGoToAbsolute, Count:=1

Selection.MoveDown Unit:=wdPageBreak, Count:=1, Extend:=wdExtend

Selection.Cut
'Copy the selection
Documents.Add
'Add a new document
Selection.Paste
'Paste
ActiveDocument.SaveAs , FileFormat:=wdFormatDocument
'Save the new document using first line as file name
ActiveDocument.Close
'Close this new document
Documents(sCurrentDoc).Activate
'Activate the document where we started from
Next i
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com