How to split document into multiple documents in word?

To split a Word document into multiple documents, you can use VBA (Visual Basic for Applications) to automate the process. Here are two methods:

1. Split Word Document by Specified Delimiter with VBA:

This method involves splitting the document based on a specified delimiter.

  1. Press Alt + F11 to open the VBA editor.
  2. Click Insert > Module to add a new module.
  3. Copy and paste the following VBA code into the module:
Sub SplitNotes(delim As String, strFilename As String)
Dim doc As Document
Dim arrNotes
Dim I As Long
Dim X As Long
Dim Response As Integer
arrNotes = Split(ActiveDocument.Range, delim)
Response = MsgBox(“This will split the document into ” & UBound(arrNotes) + 1 & ” sections. Do you wish to proceed?”, 4)

If Response = 7 Then Exit Sub

For I = LBound(arrNotes) To UBound(arrNotes)
If Trim(arrNotes(I)) <> “” Then
X = X + 1
Set doc = Documents.Add
doc.Range = arrNotes(I)
doc.SaveAs ThisDocument.Path & “\” & strFilename & Format(X, “000”)
doc.Close True
End If
Next I
End Sub

Sub test()
‘Delimiter & filename
SplitNotes “///”, “Notes “
End Sub

How to split document into multiple documents in word

How to split document into multiple documents in word


  1. Replace "///" with your desired delimiter (e.g., “===”).
  2. Replace "Notes " with your desired filename prefix.
  3. Run the macro by clicking Run or pressing F5.

2. Split Word Document by Page with VBA:

This method involves splitting the document by page.

  1. Press Alt + F11 to open the VBA editor.
  2. Click Insert > Module to add a new module.
  3. Copy and paste the following VBA code into the module:
Sub SplitIntoPages()
Dim docMultiple As Document
Dim docSingle As Document
Dim rngPage As Range
Dim iCurrentPage As Integer
Dim iPageCount As Integer
Dim strNewFileName As String
Application.ScreenUpdating = False

Set docMultiple = ActiveDocument
Set rngPage = docMultiple.Range
iCurrentPage = 1

iPageCount = docMultiple.Content.ComputeStatistics(wdStatisticPages)

Do Until iCurrentPage > iPageCount
If iCurrentPage = iPageCount Then
rngPage.End = ActiveDocument.Range.End
Else
Selection.GoTo wdGoToPage, wdGoToAbsolute, iCurrentPage + 1
rngPage.End = Selection.Start
End If

rngPage.Copy
Set docSingle = Documents.Add
docSingle.Range.Paste
docSingle.Range.Find.Execute Findtext:=”^m”, ReplaceWith:=””

strNewFileName = Replace(docMultiple.FullName, “.doc”, “_” & Right$(“000” & iCurrentPage, 4) & “.doc”)
docSingle.SaveAs strNewFileName
iCurrentPage = iCurrentPage + 1
docSingle.Close

rngPage.Collapse wdCollapseEnd
Loop

Application.ScreenUpdating = True

Set docMultiple = Nothing
Set docSingle = Nothing
Set rngPage = Nothing
End Sub

  1. Run the macro by clicking Run or pressing F5.

These methods will split your Word document into multiple documents based on the specified criteria. Adjust the parameters in the code to fit your needs.

Gotkey.net
Logo
Compare items
  • Total (0)
Compare
0
Shopping cart