I posted this on Woody's as well, but have gotten no replies as yet. What I would like to do is split a 200+ word document into 200+ separate documents each representing a page from the former larger document. Any ideas?
Thanks in advance.
Splitting a Word Document
-
- PlatinumLounger
- Posts: 5409
- Joined: 24 Jan 2010, 08:33
- Location: A cathedral city in England
Re: Splitting a Word Document
I won't make the joke that splitting a 200-word document into 200 pages would only give one word per page...
It sounds like an easy job for those who understand macros in Word.
It sounds like an easy job for those who understand macros in Word.
John Gray
"(or one of the team)" - how your hospital appointment letter indicates that you won't be seeing the Consultant...
"(or one of the team)" - how your hospital appointment letter indicates that you won't be seeing the Consultant...
-
- Administrator
- Posts: 78524
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Splitting a Word Document
Hi Jeff,
Welcome to Eileen's Lounge!
Here is a macro you can use. It's best to store it in a module in another document or in your Normal.dot(m), for the macro will close the active document.
Make sure that the document that you want to split is the active document when you run the macro.
Welcome to Eileen's Lounge!
Here is a macro you can use. It's best to store it in a module in another document or in your Normal.dot(m), for the macro will close the active document.
Make sure that the document that you want to split is the active document when you run the macro.
Code: Select all
Sub SplitPages()
Dim lngPage As Long
Dim docCur As Document
Dim docNew As Document
Dim strName As String
Dim lngPos As Long
Application.ScreenUpdating = False
Set docCur = ActiveDocument
' Get name of document
strName = docCur.FullName
' Remove extension
lngPos = InStrRev(strName, ".doc")
If lngPos > 0 Then
strName = Left(strName, lngPos - 1)
End If
' Go to start of document
Selection.HomeKey Unit:=wdStory
Do While docCur.Content.End > 1
docCur.Bookmarks("\page").Range.Cut
lngPage = lngPage + 1
Set docNew = Documents.Add
docNew.Content.Paste
docNew.SaveAs FileName:=strName & "_Page" & lngPage
docNew.Close SaveChanges:=False
docCur.Activate
Loop
Application.ScreenUpdating = True
' Optional
docCur.Close SaveChanges:=False
End Sub
Best wishes,
Hans
Hans
-
- 2StarLounger
- Posts: 168
- Joined: 25 Apr 2010, 14:12
Re: Splitting a Word Document
Thanks Hans. How do I store it in my Normal.dotm file? I didn't know I had one!
Thanks again
Thanks again
-
- Administrator
- Posts: 78524
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Splitting a Word Document
The default template is named Normal.dot in Word 2003 and before, and Normal.dotm in Word 2007 or later.
To store a macro there:
To store a macro there:
- Press Alt+F11 to activate the Visual Basic Editor.
- Click on Normal in the project explorer on the left hand side.
- Select Insert | Module to create a new code module.
- Copy/paste the code into the module.
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans
Hans
-
- 2StarLounger
- Posts: 168
- Joined: 25 Apr 2010, 14:12
Re: Splitting a Word Document
Thaks again Hans. By the way, where are the new documents stored?
-
- Administrator
- Posts: 78524
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Splitting a Word Document
Hi Jeff,
The documents are stored in the same folder as the original document, and if the original document is named for example Report.doc, the separate documents will be named Report_Page1.doc, Report_Page2.doc etc.
The documents are stored in the same folder as the original document, and if the original document is named for example Report.doc, the separate documents will be named Report_Page1.doc, Report_Page2.doc etc.
Best wishes,
Hans
Hans
-
- 2StarLounger
- Posts: 168
- Joined: 25 Apr 2010, 14:12
Re: Splitting a Word Document
Thaks again. Great macro!
-
- Administrator
- Posts: 78524
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Splitting a Word Document
Could you mention in your thread in the Windows Secrets Lounge (Breaking Up a Document) that the problem has been solved? Thanks in advance!
Best wishes,
Hans
Hans
-
- 2StarLounger
- Posts: 168
- Joined: 25 Apr 2010, 14:12
Re: Splitting a Word Document
Abvsolutely!