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 / August 2006

Tip: Looking for answers? Try searching our database.

splitting doc file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mark13.pl@gmail.com - 23 Aug 2006 13:26 GMT
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
Graham Mayor - 23 Aug 2006 14:02 GMT
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

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Hello,
>
[quoted text clipped - 5 lines]
>
> Thank you, mark
mark13.pl@gmail.com - 23 Aug 2006 14:55 GMT
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
Doug Robbins - Word MVP - 23 Aug 2006 18:55 GMT
Close the original file without saving it.  Then open it again.

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

> Hello,
>
[quoted text clipped - 9 lines]
>
> Thank you, mark
mark13.pl@gmail.com - 23 Aug 2006 20:24 GMT
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
Doug Robbins - Word MVP - 23 Aug 2006 21:28 GMT
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

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

> Hello,
>
[quoted text clipped - 6 lines]
>
> Regards, mark
 
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.