Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2005

Tip: Looking for answers? Try searching our database.

Macro to cut a big document into smallers ones.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
olemaitre@legermarketing.com - 08 Nov 2005 16:18 GMT
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?
Tony Jollans - 08 Nov 2005 18:04 GMT
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.

--
Enjoy,
Tony

> 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?
olemaitre@legermarketing.com - 08 Nov 2005 18:16 GMT
Yes I agree, but it's not a 1 time thing, I have to do that often so
that why I was aking that
Tony Jollans - 08 Nov 2005 20:34 GMT
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

--
Enjoy,
Tony

> Yes I agree, but it's not a 1 time thing, I have to do that often so
> that why I was aking that
olemaitre@legermarketing.com - 08 Nov 2005 22:47 GMT
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

> OK, try this then ..
>
[quoted text clipped - 34 lines]
> > Yes I agree, but it's not a 1 time thing, I have to do that often so
> > that why I was aking that
Tony Jollans - 08 Nov 2005 23:34 GMT
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

--
Enjoy,
Tony

> 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.
[quoted text clipped - 38 lines]
> > > Yes I agree, but it's not a 1 time thing, I have to do that often so
> > > that why I was aking that
olemaitre@legermarketing.com - 08 Nov 2005 23:56 GMT
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 :)
Tony Jollans - 09 Nov 2005 00:19 GMT
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

--
Enjoy,
Tony

> 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 :)
olemaitre@legermarketing.com - 08 Nov 2005 23:02 GMT
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

> OK, try this then ..
>
[quoted text clipped - 34 lines]
> > Yes I agree, but it's not a 1 time thing, I have to do that often so
> > that why I was aking that
Richard Lawson - 08 Nov 2005 23:23 GMT
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.

> 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.
[quoted text clipped - 39 lines]
>> > Yes I agree, but it's not a 1 time thing, I have to do that often so
>> > that why I was aking that
Doug Robbins - Word MVP - 09 Nov 2005 05:24 GMT
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

Signature

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

>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
[quoted text clipped - 44 lines]
>>> > Yes I agree, but it's not a 1 time thing, I have to do that often so
>>> > that why I was aking that
Charles Kenyon - 09 Nov 2005 18:08 GMT
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.
Signature

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

See also the MVP FAQ: http://word.mvps.org/FAQs/ which is awesome!
--------- --------- --------- --------- --------- ---------
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.

> 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?
Richard Lawson - 15 Nov 2005 21:09 GMT
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

> Take a look at the macro at
> http://gmayor.com/individual_merge_letters.htm. It may give you a good
[quoted text clipped - 3 lines]
>> more little documents. Is it possible if, for exemple, I want to cut a
>> 1200 pages documents into 6 documents of 200 pages?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.