Splitting a doc after break lines

N

Nicolas

Hello,

I have a doc file with 50 lyrics of songs.I would like to have one .doc per
song. A break line appears after each song.

I can't figure how to make the macro taking the text till the next break
line, cutting it and pasting and saving it in a new document (having the
name of the 1st line ie the song's title).

Thanks if you can help.

Nicolas
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Nicolas,

I assume that the break lines you are talking about are page breaks. If
that's the case, use

Dim Pages As Long, DocName As Range
Selection.HomeKey Unit:=wdStory
Pages = ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)
Counter = 0
While Counter < Pages
Counter = Counter + 1
Set DocName = ActiveDocument.Paragraphs.First.Range
DocName.End = DocName.End - 1
ActiveDocument.Bookmarks("\Page").Range.Cut
Documents.Add
Selection.Paste
ActiveDocument.SaveAs FileName:=DocName, FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="",
AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
ActiveWindow.Close
Wend

This assumes that title is the first paragraph on the page and that a song
fits all on one page. If it doesn't, I would use Edit>Replace to replace
the manual page breaks with section breaks, and then use:

Dim Letters As Integer, Counter As Integer, DocName as Rnage
Letters = ActiveDocument.Sections.Count
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter < Letters
Set DocName = ActiveDocument.Sections.First.Range.Paragraphs.First.Range
DocName.End = DocName.End - 1
ActiveDocument.Sections.First.Range.Cut
Documents.Add
Selection.Paste
ActiveDocument.Sections(2).PageSetup.SectionStart = wdSectionContinuous
ActiveDocument.SaveAs FileName:=DocName, FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="",
AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
ActiveWindow.Close
Counter = Counter + 1
Wend


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top