Save each section to a separte file

M

Martin

My brother regularly receives a large word document which is organised
as a series of sections - one section per page.

Is it possible to write some VBA to open myfile.doc and write out each
section to it's own file e.g. myfile.001.doc, myfile.002.doc, etc?

I've fished around in Word 97's object model here at home but I can't
spot the solution.

I'd really appreciate any help,

Martin
 
S

Sriraman CS

Here is the code:

Sub SplitSectionsIntoMultipleDoc()
'---------------------------------------------------------------------------------------
' Procedure : SplitSectionsIntoMultipleDoc
' DateTime : 4/7/2006 10:49
' Author : Sriraman CS
' Purpose : To Split each setion from the source document into multiple
documents
'---------------------------------------------------------------------------------------
'
Dim rngSourceDoc As Range
Dim oSection As Section
Dim strPath As String
Dim intCount As Integer

On Error GoTo SplitSectionsIntoMultipleDoc_Error

Application.ScreenUpdating = False
strPath = ActiveDocument.Path
intCount = 1
Set rngSourceDoc = ActiveDocument.Range(ActiveDocument.Range.Start,
ActiveDocument.Range.End)
For Each oSection In rngSourceDoc.Sections
Documents.Add
oSection.Range.Copy
With ActiveDocument
.Range.Paste
.SaveAs strPath & "\File" & intCount & ".doc", wdFormatDocument
.Close
End With
intCount = intCount + 1
Next
Set rngSourceDoc = Nothing

ExitHere:
Application.ScreenUpdating = True
On Error GoTo 0
Exit Sub

SplitSectionsIntoMultipleDoc_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
SplitSectionsIntoMultipleDoc of Module NewMacros"
End Sub

Regards,

CS.
 

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