Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split document into many files Word 2003

Status
Not open for further replies.

ReillyC

MIS
Feb 6, 2004
114
US
I need help badly.
I have a word document that is 357 pages. Within the document there are several file groups about 200.

For example,
File2369933 on pages 1 - 3
File9663339 on page 4
File2173993 on pages 5-9

I need to separate each file group into it's own document.
For example,
File2369933.doc
File9663339.doc
File2173993.doc

The file group names appear in the header of each page. Can someone help with a macro?

I found a Separate File by Page macro on the Microsoft website but I'm not sure how to adjust it for my needs.

The following macro copies text one page at a time and saves that text in a new document. The macro uses the pre-defined bookmark "\page" and the document's built-in property of "number of pages".

Sub BreakOnPage()
' Used to set criteria for moving through the document by page.
Application.Browser.Target = wdBrowsePage

For i = 1 To ActiveDocument.BuiltInDocumentProperties("Number of Pages")

'Select and copy the text to the clipboard.
ActiveDocument.Bookmarks("\page").Range.Copy

' Open new document to paste the content of the clipboard into.
Documents.Add
Selection.Paste
' Removes the break that is copied at the end of the page, if any.
Selection.TypeBackspace
ChangeFileOpenDirectory "C:\"
DocNum = DocNum + 1
ActiveDocument.SaveAs FileName:="test_" & DocNum & ".doc"
ActiveDocument.Close

' Move the selection to the next page in the document.
Application.Browser.Next
Next i
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub

Many thanks

 


Hi,

I'm no expert when it comes to Word, but take a look at Sections in your document.

Each Section has it's own header/footer. Section is an Object within the Document. For instance you can do...
Code:
Dim oSec as Section
for each oSec in ActiveDocument.Sections
   With oSec.Heading
'stuff relating the the section header
   End with
Next
Header/Footer is a Property of Section.

I would imagine that using Section.Range you can bite off the TEXT in the section and all the other formating as well, in order to put it into a new document.

Hope that helps.



Skip,

[glasses] [red]Sign above the facsimile apparatus at the music publisher:[/red]
If it ain't baroque...
Don't FAX it![tongue]
 
Thanks for the hints. Would you recommend some sites where they explain the basics of VBA for Word?

Cheers!
 
There are some experts in the VBA Forum707.

Also -- search on vba, word as a start.

Skip,

[glasses] [red]Sign above the facsimile apparatus at the music publisher:[/red]
If it ain't baroque...
Don't FAX it![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top