Provided there are no section breaks in the document, the following will
split the document at each Times New Roman Bold 12 title into separate files
named according to that title with the addition of a number into a folder
d:\My Documents\Test\Merge. Change that folder path where indicated to some
suitable location on your hard drive. May I suggest that you work with a
COPY of the document!!! http://www.gmayor.com/installing_macro.htm
Sub SplitAtFont()
Dim mask As String
Letters = Selection.Information(wdActiveEndSectionNumber)
With Selection
.HomeKey Unit:=wdStory
.MoveDown Unit:=wdLine
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Font.name = "Times New Roman"
.Font.Size = "12"
.Font.Bold = True
.Wrap = wdFindStop
Do While .Execute
With Selection
.HomeKey Unit:=wdLine
.InsertBreak Type:=wdSectionBreakContinuous
.MoveDown Unit:=wdLine
End With
Loop
End With
.EndKey Unit:=wdStory
.InsertBreak Type:=wdSectionBreakContinuous
End With
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter < Letters
Application.ScreenUpdating = False
With Selection
.HomeKey Unit:=wdStory
.EndKey Unit:=wdLine, Extend:=wdExtend
.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
End With
sName = Selection
'***********************************
docName = "D:\My Documents\Test\Merge\" & sName & Counter & ".doc"
'***********************************
ActiveDocument.Sections.First.Range.Cut
Documents.Add
With Selection
.Paste
.HomeKey Unit:=wdStory
.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
.Delete
End With
ActiveDocument.SaveAs FileName:=docName, _
FileFormat:=wdFormatDocument
ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
End Sub

Signature
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Hi
>
[quoted text clipped - 28 lines]
> ofcourse some sample code will help, since this is the first time I
> am using VBA? Thanks for the help
Saad - 20 Feb 2008 22:54 GMT
Hey thanks I havn't checked this code yet but will do in morning, and yea
document has sections but I can either first split it on basis of sections
using foreach or I can do it manually theer arnt many sections
thanks again
Saad - 21 Feb 2008 12:05 GMT
Hello Graham , I am afraid there is something slightly wrong with my file or
code because the code gets stuck in an infinite loop. Plus I am not able to
understand the code otherwise would have had solved the problem, is there any
reference or starting tutorial on VBA and Word Objects?
Thanks
Graham Mayor - 21 Feb 2008 15:53 GMT
Probably a bit of both :)
I have tidied the code up and annotated it. See if that helps. It would help
to replace any section breaks with a paragraph break first. ie replace ^b
with ^p as section breaks will confuse the second part of the macro.
Sub SplitAtFont()
Dim Letters As Integer
Dim Counter As Long
Dim sName As String
Dim docName As String
Application.ScreenUpdating = False
With Selection
.HomeKey Unit:=wdStory 'move to the start of the document
.MoveDown Unit:=wdLine 'move down one line
With .Find 'locate Times New Roman 12 point Bold
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Font.name = "Times New Roman"
.Font.Size = "12"
.Font.Bold = True
.Wrap = wdFindStop
Do While .Execute ' and when found
With Selection
.HomeKey Unit:=wdLine 'move to the start of the line
'and insert a section break
.InsertBreak Type:=wdSectionBreakContinuous
.MoveDown Unit:=wdLine 'move down one line
End With
Loop ' then find the next TNR 12 pont Bold
End With
.EndKey Unit:=wdStory ' go to the end of the document
' and add a section break
.InsertBreak Type:=wdSectionBreakContinuous
End With
'define what Letters is
Letters = Selection.Information(wdActiveEndSectionNumber)
'go to the top of tyeh document
Selection.HomeKey Unit:=wdStory
Counter = 1 'set a counter
While Counter < Letters 'set the limits of the counter
Application.ScreenUpdating = False
With Selection 'grab some of the first line as a filename
.HomeKey Unit:=wdStory
.EndKey Unit:=wdLine, Extend:=wdExtend
.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
End With
sName = Selection 'and apply it to a variable
'***********************************
'Format the name for the split document
docName = "D:\My Documents\Test\Merge\" & sName & Counter & ".doc"
'***********************************
'Cut the first section to the clipboard
ActiveDocument.Sections.First.Range.Cut
Documents.Add 'open a new document
Selection.Paste ' and paste the clipboard content
'Save the document with the chosen filename
ActiveDocument.SaveAs FileName:=docName, _
FileFormat:=wdFormatDocument
ActiveWindow.Close 'and close it
Counter = Counter + 1 'increment the counter
'Then go round again
Wend
Application.ScreenUpdating = True
End Sub

Signature
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Hello Graham , I am afraid there is something slightly wrong with my
> file or code because the code gets stuck in an infinite loop. Plus I
[quoted text clipped - 3 lines]
>
> Thanks