Hi,
I hope everyone's day is going well!
I am trying to fix some code unsuccessfully to split documents by headings.
I have tested a number of macros for splitting documents, available here and elsewhere, but they fall short on one feature that I need:
Saving the file name AS the heading name.
You can split by Section or Page as referenced here.
There are others that split by delimiter.
https://support.microsoft.com/en-us/kb/306348
I found a macro from this forum and have been fiddling about testing it – the code refuses to co-operate.
It splits the documents - but you have to give it an initial file name.
The problem is that with this approach - I don’t know what’s inside my files, so it creates more problems for me than solves.
https://www.msofficeforums.com/word-...documents.html
The above macro with initial file name test outputs as :
Test1
Test2
Test3
Test4
It also has some other call to functions - I am not sure what for.
I am stuck on the below - code from macro above - and not sure - how to fix it
Code:
Dim heading As Long
If Selection.Style = "Heading 1" Then
Set Rng = aDoc.Range(Rng1.Start, Rng2.End)
Set bDoc = Documents.Add
bDoc.Content.FormattedText = Rng
'bDoc.SaveAs Ans$ & Counter, wdFormatDocument
'bDoc.SaveAs aDoc.path & "\" & Ans$ & Counter,
wdFormatDocument
ActiveDocument.SaveAs FilePath & "\" & FileName(heading) & ".docx"
bDoc.Close
To Recap:
I am trying to split a large document by its headings
· Split Files by Heading 1
· Save each split file with the heading name
I would be very grateful for some guidance, as always thanking you for the time and expertise shared is greatly appreciated.
Thank you so much in advance for your time.
J