Hi All!
Just wondering if any of you could quickly help me with a problem I'm having.
I am using the BreakOnSection macro (see code below) which breaks up sections in my document and saves them as individual files. But instead of naming files "test_1", "test_2" "test_3" etc. I want to use the first line of each section for the file name.
Note: The first line will always have the same format, but the text will always change. Here is an example of one (without quotes):
"June 20 7pm - Coldplay, GM Place, Vancouver, BC"
Please see the code below to get a feel for what I'm working with, and if any of you could help, that would be greatly appreciated!
Code:
Sub BreakOnSection()
' Used to set criteria for moving through the document by section.
Application.Browser.Target = wdBrowseSection
'A mail merge document ends with a section break next page.
'Subtracting one from the section count stop error message.
For i = 1 To ((ActiveDocument.Sections.Count) - 1)
'Note: If a document does not end with a section break,
'substitute the following line of code for the one above:
'For I = 1 To ActiveDocument.Sections.Count
'Select and copy the section text to the clipboard.
ActiveDocument.Bookmarks("\Section").Range.Copy
'Create a new document to paste text from clipboard.
Documents.Add
Selection.Paste
' Removes the break that is copied at the end of the section, if any.
Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
ChangeFileOpenDirectory "C:\"
DocNum = DocNum + 1
ActiveDocument.SaveAs FileName:="test_" & DocNum & ".doc"
ActiveDocument.Close
' Move the selection to the next section in the document.
Application.Browser.Next
Next i
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub