Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 11-16-2015, 01:40 PM
jc491's Avatar
jc491 jc491 is offline Word VBA  - Split Document By Headings - Save File Name As Heading Name Windows 7 64bit Word VBA  - Split Document By Headings - Save File Name As Heading Name Office 2013
VBA Novice
Word VBA  - Split Document By Headings - Save File Name As Heading Name
 
Join Date: Sep 2015
Location: UK
Posts: 55
jc491 is on a distinguished road
Default Word VBA - Split Document By Headings - Save File Name As Heading Name

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
Reply With Quote
 

Tags
document, heading, split



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word VBA  - Split Document By Headings - Save File Name As Heading Name split word document based on bookmarks with each new document title of the bookmark megatronixs Word VBA 9 09-05-2020 02:29 PM
Word VBA  - Split Document By Headings - Save File Name As Heading Name How to Restore Heading 1, Heading 2, etc. within a Word Document cheech1981 Word 9 01-11-2017 02:14 AM
Word VBA  - Split Document By Headings - Save File Name As Heading Name How can I save a Word Document as a PDF file with a merged field filename? kp2009 Word VBA 5 08-27-2015 11:45 PM
Word VBA  - Split Document By Headings - Save File Name As Heading Name Split multi-page mail merge document, then name file from letter info. BriMan83 Mail Merge 1 04-24-2013 11:35 PM
Word VBA  - Split Document By Headings - Save File Name As Heading Name Macro to create new word doc and save the file using String found in the document VBNation Word VBA 2 02-08-2013 07:14 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:46 AM.


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