Created
April 12, 2014 20:28
-
-
Save druedin/10555220 to your computer and use it in GitHub Desktop.
This is a modified VBA script for splitting MS Word documents. The original is from http://www.extendoffice.com/documents/word/966-word-split-document-into-multiple-documents.html apparently from http://www.vbaexpress.com/kb/getarticle.php?kb_id=922 (user lucas). I am unable to determine a licence, and share the code here to highight the few cha…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
'Encoding:=1252 | |
'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