splitting doc file

M

mark13.pl

Hello,

I have a large file (about 100 pages) which I have to split page by
page. For example having a file: example.doc (5 pages) I want to run
script which generate me 5 files (example1.doc,
example2.doc,...,example5.doc) each containing just one page from
oryginal file. Is it possible to do so in Visual Basic?!?

Thank you, mark
 
G

Graham Mayor

Change the target location at Docname and the default filename sName to suit
your requirements

Sub SplitByPage()
Dim mask As String
Letters = ActiveDocument.Bookmarks("\page").Range
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter < Letters
Application.ScreenUpdating = False
sName = "Split"
Docname = "D:\My Documents\Test\Merge\" _
& sName & LTrim$(Str$(Counter)) & ".doc"
On Error GoTo oops:
ActiveDocument.Bookmarks("\page").Range.Cut
Documents.Add
With Selection
.Paste
.EndKey Unit:=wdStory
.MoveLeft Unit:=wdCharacter, Count:=1
.Delete Unit:=wdCharacter, Count:=1
End With
ActiveDocument.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDocument
ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
oops:
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
M

mark13.pl

Hello,
Change the target location at Docname and the default filename sName to suit
your requirements

WoW! Great :).
Unfortunately SplitByPage just save first page in different file and
remove it from the oryginal file. I would need something else: just
save all the pages in different files without modyfing oryginal file.
Can your script be modyfied so that it would split all the pages?!?

Thank you, mark
 
D

Doug Robbins - Word MVP

Close the original file without saving it. Then open it again.

--
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
 
M

mark13.pl

Hello,
Close the original file without saving it. Then open it again.

Yep, with oryginal file there is no problem. But still this script
creates only one file (split1.doc) even if there are 10 or more pages
in oryginal file. I use Microsoft Word 2000 (9.0.2812). Any ideas what
can be wrong?!?

Regards, mark
 
D

Doug Robbins - Word MVP

Use this one

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
 

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