Macro to cut a big document into smallers ones.

O

olemaitre

Hi everyone, I need a macro to cut a big word document en save it in
more little documents. Is it possible if, for exemple, I want to cut a
1200 pages documents into 6 documents of 200 pages?
 
T

Tony Jollans

It's certainly possible but it really isn't worth the effort just to split a
single document into six.

Cut the first 200 pages into a new document, save it, repeat 5 times.
 
O

olemaitre

Yes I agree, but it's not a 1 time thing, I have to do that often so
that why I was aking that
 
T

Tony Jollans

OK, try this then ..

You can change the number of pages in each small file where shown
Also you need to change it to save in your own path, again where shown

Sub SplitBigDoc()
Dim BigDoc As Document, NewDoc As Document
Dim SeqNo As Integer
Set BigDoc = ActiveDocument
SeqNo = 0
Application.ScreenUpdating = False
While Len(BigDoc.Content.Text) > 1
With Selection
.GoTo wdGoToPage, wdGoToAbsolute, 200 ' <=== Number of Pages here
.HomeKey wdStory, True
If Selection.Information(wdActiveEndPageNumber) <> 200 Then
BigDoc.Content.Select
.Cut
Set NewDoc = Documents.Add
With NewDoc
.Content.Paste
SeqNo = SeqNo + 1
.SaveAs "Part" & SeqNo & ".doc" ' <=== Full Path and Name here
.Close
End With
End With
Wend
Application.ScreenUpdating = True
Set NewDoc = Nothing
Set BigDoc = Nothing
End Sub
 
O

olemaitre

Tx for the help Tony but something is not working. I think that a end
if is missing somewhere. I'm trying to find where but no luck so far.
If you could check it, I will really appreciate
 
O

olemaitre

Tx for the help Tony but something is not working. I think that a end
if is missing somewhere. I'm trying to find where but no luck so far.
If you could check it, I will really appreciate
 
R

Richard Lawson

I would like to know how this works out. I have a project where a dozen
people run reports many times a day. The result is a single Word document
which then has to be broken into single pages and saved.
 
T

Tony Jollans

It wasn't actually missing an EndIf - it was just the way the text got split
in the posting. But I have now broken the line and added an end if and this
shouldn't get split anymore.

Sub SplitBigDoc()
Dim BigDoc As Document, NewDoc As Document
Dim SeqNo As Integer
Set BigDoc = ActiveDocument
SeqNo = 0
Application.ScreenUpdating = False
While Len(BigDoc.Content.Text) > 1
With Selection
.GoTo wdGoToPage, wdGoToAbsolute, 200 ' <=== Number of Pages here
.HomeKey wdStory, True
If Selection.Information(wdActiveEndPageNumber) <> 200 Then
BigDoc.Content.Select
End If
.Cut
Set NewDoc = Documents.Add
With NewDoc
.Content.Paste
SeqNo = SeqNo + 1
.SaveAs "Part" & SeqNo & ".doc" ' <=== Full Path and Name here
.Close
End With
End With
Wend
Application.ScreenUpdating = True
Set NewDoc = Nothing
Set BigDoc = Nothing
End Sub
 
O

olemaitre

Tx again to have answered so fast. I'm must probably be pretty dumb I'm
not able to get it to work. I have changed the path, that's setting is
ok but even if change numer of page, it always give me only 1 file
with all the content in it. I have tried changind the <>200 but no luck
either. Can you tell me what am I doing wrong? Tx a lot :)
 
T

Tony Jollans

Having to guess abit here - if this doesn't help can you post the exact code
you're using and say what Word version you have.

The code generates unique file names using a sequential number (SeqNo).
Might you have replaced that when you added your path?

It might also be worth trying changing ..

If Selection.Information(wdActiveEndPageNumber) <> 200 Then

To

If Selection.Information(wdActiveEndPageNumber) < 200 Then
 
D

Doug Robbins - Word MVP

Sub splitter()

'

' splitter Macro

' Macro created 16-08-98 by Doug Robbins to save each page of a document

' as a separate file with the name Page#.DOC

'

Dim Counter As Long, Source As Document, Target As Document

Set Source = ActiveDocument

Selection.HomeKey Unit:=wdStory

Pages = Source.BuiltInDocumentProperties(wdPropertyPages)

Counter = 0

While Counter < Pages

Counter = Counter + 1

DocName = "Page" & Format(Counter)

Source.Bookmarks("\Page").Range.Cut

Set Target = Documents.Add

Target.Range.Paste

Target.SaveAs FileName:=DocName

Target.Close

Wend

End Sub

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
C

Charles Kenyon

Take a look at the macro at http://gmayor.com/individual_merge_letters.htm.
It may give you a good start. It is designed to split a mailmerge result
document into separate documents.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
R

Richard Lawson

Fantastic. I have never done vba but I have done VB and ASP. This should be
fun. I will let you know how it goes.

Rich
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top