Microsoft Office Tutorials and References
In Depth Information
Splitting a Document into Multiple Files
'Saving automatically saves subdocs¶
'to names using text of first paragraph¶
doc.Save¶
'''Save merge result to¶
'''separate files¶
' Convert all sections to Subdocs¶
' (for mail merge result, for example)¶
'AllSectionsToSubDoc(doc)¶
' Save each Subdoc as a separate file¶
'SaveAllSubDocsFromMerge¶
End Sub¶
' * * * * *¶
Sub SplitByLevel(doc As Word.Document)¶
'Variable declaration¶
Dim outlineLevel As String¶
Dim i As Long¶
Dim rngSearch As Word.Range¶
Dim styleName¶
Dim bFound As Boolean¶
outlineLevel = InputBox( _¶
"From which heading level do you want to " & _¶
"split the document into separate documents?")¶
'Invalid entry: outline levels from 1 to 9¶
If outlineLevel = "" Then¶
Exit Sub¶
ElseIf CLng(outlineLevel) < 1 _¶
Or CLng(outlineLevel) > 9 Then¶
Exit Sub¶
End If¶
'Must be in MasterView to work with¶
'Subdocs as separate files¶
With doc.ActiveWindow.View¶
.Type = wdMasterView¶
'And all text must be showing¶
.ShowHeading 9¶
.ShowAllHeadings¶
End With¶
For i = 1 To CLng(outlineLevel)¶
Set rngSearch = doc.Range¶
styleName = GetStyleName(doc, i)¶
Do¶
With rngSearch.Find¶
.ClearFormatting¶
.Forward = True¶
.Format = True¶
.MatchCase = False¶
.MatchWholeWord = False¶
.MatchWildcards = False¶
.Style = styleName¶
.Text = ""¶
.Wrap = wdFindStop¶
Wrd
Search JabSto ::




Custom Search