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

Tip: Looking for answers? Try searching our database.

Macro Help: Splitting each page so that each page is an individual word document

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
cardioblack@gmail.com - 15 Dec 2006 17:43 GMT
Hi,

I am in need of help on building a macro that will take multi page
document and splitting each page so that each page would be an
individual word document. Any help would be great. Thanks!
Doug Robbins - Word MVP - 15 Dec 2006 19:35 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

> Hi,
>
> I am in need of help on building a macro that will take multi page
> document and splitting each page so that each page would be an
> individual word document. Any help would be great. Thanks!
cardioblack@gmail.com - 15 Dec 2006 19:47 GMT
Thank you so much for responding so quickly!

I tried running the macro on a word document that I have.

An error generates : Run-Time Error '5690'
             The Selection is marked as deleted text

When I click debug -    Source.Bookmarks("\Page").Range.Cut

is highlighted.

If you need any more information, I'd be happy to help. I'm going to
try it on another document for now to see if it works on that one
instead.

> Sub splitter()
>
[quoted text clipped - 51 lines]
> > document and splitting each page so that each page would be an
> > individual word document. Any help would be great. Thanks!
cardioblack@gmail.com - 15 Dec 2006 19:52 GMT
I tried it on another document. It seemed to have worked however the
files saved to a specific location.

My screen would show a document under name doc1.doc ,  doc2.doc  ,
doc3.doc appear and disappear from the screen but I don't find it
anywhere in my hard drive.
Doug Robbins - Word MVP - 16 Dec 2006 10:49 GMT
They will have been saved in the default documents folder with names like
Page1, Page2, Page3, etc.

However if you want to save them to a specific place, replace the following
line of code

DocName = "Page" & Format(Counter)

with

DocName = "[Drive]:\[Folder]\Page" & Format(Counter)

where you replace [Drive] with the drive letter and [Folder] with the folder
name

For example

DocName = "c:\splitdocuments\Page" & Format(Counter)

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 tried it on another document. It seemed to have worked however the
> files saved to a specific location.
>
> My screen would show a document under name doc1.doc ,  doc2.doc  ,
> doc3.doc appear and disappear from the screen but I don't find it
> anywhere in my hard drive.
cardioblack@gmail.com - 28 Dec 2006 13:37 GMT
Thank you so much for your help! The macro works like a charm!

Rate this thread:






 
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.