F
Fred Goldman
I'm trying to create a documents from all the text between each headin. For
example Heading1 after that is BodyText1 and BodyText2, create a single
document from that until the next Heading1 and so on.
Here's what I've got:
Dim myPara As Style
Dim myLastStyle As Style
Dim x As Long
Dim myTemplate As String
x = 1
myTemplate = Templates("C:\Templates\Chatzros Kadshechu.dot")
Set myLastStyle = ActiveDocument.Styles("LastParagraph")
Set myPara = ActiveDocument.Styles("Heading1")
Do
Do
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
'At the following line it chokes because it selects two
paragraphs
'which have two different styles
Loop While Selection.Style <> myPara
Selection.Copy
Documents.Add Template:=myTemplate
ActiveDocument.Range.PasteAndFormat wdFormatOriginalFormatting
ActiveDocument.SaveAs FileName:="D" & x
ActiveDocument.Close
x = x + 1
Selection.MoveDown Unit:=wdParagraph, Count:=1
Loop Until Selection.Style = myLastStyle
End Sub
example Heading1 after that is BodyText1 and BodyText2, create a single
document from that until the next Heading1 and so on.
Here's what I've got:
Dim myPara As Style
Dim myLastStyle As Style
Dim x As Long
Dim myTemplate As String
x = 1
myTemplate = Templates("C:\Templates\Chatzros Kadshechu.dot")
Set myLastStyle = ActiveDocument.Styles("LastParagraph")
Set myPara = ActiveDocument.Styles("Heading1")
Do
Do
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
'At the following line it chokes because it selects two
paragraphs
'which have two different styles
Loop While Selection.Style <> myPara
Selection.Copy
Documents.Add Template:=myTemplate
ActiveDocument.Range.PasteAndFormat wdFormatOriginalFormatting
ActiveDocument.SaveAs FileName:="D" & x
ActiveDocument.Close
x = x + 1
Selection.MoveDown Unit:=wdParagraph, Count:=1
Loop Until Selection.Style = myLastStyle
End Sub