Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
This is a modified VBA script for splitting MS Word documents. The original is from apparently from (user lucas). I am unable to determine a licence, and share the code here to highight the few cha…
Attribute VB_Name = "Module1"
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.SaveAs2 ThisDocument.Path & "\" & strFilename & "-" & Format(X, "000") & ".txt", FileFormat:= _
wdFormatUnicodeText, Encoding:=msoEncodingUTF8
'original code: doc.SaveAs ThisDocument.Path & "\" & strFilename & Format(X, "000")
doc.Close True
End If
Next I
End Sub
Sub test()
'delimiter & filename
' SplitNotes "///", "Notes "
'SplitNotes "///", ActiveDocument.Name
SplitNotes "///", Left$(ActiveDocument.Name, (Len(ActiveDocument.Name) - 4))
'Left$(.FullName, (Len(.FullName) - 4))
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.