Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-24-2021, 06:19 AM
Shelley Lou Shelley Lou is offline VBA to split Word document into multiple documents Windows 10 VBA to split Word document into multiple documents Office 2016
Competent Performer
VBA to split Word document into multiple documents
 
Join Date: Dec 2020
Posts: 163
Shelley Lou is on a distinguished road
Default VBA to split Word document into multiple documents

Hey guys, I have a very large document I need to split into multiple documents. Each section starts with a style called PageTitle for its main title, so I need the code to split for every PageTitle instances throughout the document. I've found some code online and wondered how I can update it. I also need the documents to be saved to my H:/ drive in a specific folder. Any help would be appreciated. Many thanks, Shelley



Code:
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
Reply With Quote
  #2  
Old 02-24-2021, 07:11 AM
gmaxey gmaxey is offline VBA to split Word document into multiple documents Windows 10 VBA to split Word document into multiple documents Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,422
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

You might start with this. I haven't used it in awhile so not sure if it will do your job or not:


Document Splitter
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA to split Word document into multiple documents split word document based on bookmarks with each new document title of the bookmark megatronixs Word VBA 9 09-05-2020 02:29 PM
Extract Document ID and description from header in multiple Word documents and paste in new word doc venkat_m Word VBA 2 05-23-2020 03:57 AM
VBA to split Word document into multiple documents Mail Merge - split merged documents and rename each split document based on text in header FuriousD Word VBA 1 05-12-2019 04:06 AM
Switch between multiple Word documents within the same Word document kai Word VBA 2 11-20-2017 10:13 PM
Split one Word Document into Multiple PDFs VieraOfficeUser Word 3 07-30-2014 10:58 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:20 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft