Microsoft Office Tutorials and References
In Depth Information
Splitting a Document into Multiple Files
' * * * * *¶
Function AllSectionsToSubDoc(ByRef doc As Word.Document) As Boolean¶
'Variable declaration¶
Dim secCounter As Long¶
Dim NrSecs As Long¶
NrSecs = doc.Sections.Count¶
If NrSecs <= 1 Then¶
AllSectionsToSubDoc = False¶
Exit Function¶
End If¶
'Start from the end because creating¶
'Subdocs inserts additional sections¶
For secCounter = NrSecs - 1 To 1 Step -1¶
doc.Subdocuments.AddFromRange _¶
doc.Sections(secCounter).Range¶
Next secCounter¶
AllSectionsToSubDoc = True¶
End Function¶
' * * * * *¶
Sub SaveAllSubDocsFromMerge(ByRef doc As Word.Document)¶
'Variable declaration¶
Dim subdoc As Word.Subdocument¶
Dim newdoc As Word.Document¶
Dim docCounter As Long¶
docCounter = 1¶
For Each subdoc In doc.Subdocuments¶
Set newdoc = subdoc.Open¶
'Remove NextPage section breaks¶
'originating from mailmerge¶
RemoveAllSectionBreaks newdoc¶
With newdoc¶
.SaveAs FileName:="MergeResult" & CStr(docCounter)¶
.Close¶
End With¶
docCounter = docCounter + 1¶
Next subdoc¶
End Sub¶
' * * * * *¶
Sub RemoveAllSectionBreaks(doc As Word.Document)¶
With doc.Range.Find¶
.ClearFormatting¶
.Text = "^b"¶
With .Replacement¶
.ClearFormatting¶
.Text = ""¶
End With¶
.Execute Replace:=wdReplaceAll¶
End With¶
End Sub¶
Wrd
Search JabSto ::




Custom Search