F
Fred Goldman
Ok, I've been working almost forever on this code, but I can't get it to
work. What I'm trying to do is copy all the text between each heading (which
is tagged with a paragraph style named "Parsha") create a new document and
paste the text into the new document. Then loop it through all the headings.
Where I keep running into a problem is when it selects text that has more
than one style it gets confused with the Do Until statement. I think the
solution is to use the Range object, but I'm not familiar enough with it to
figure out how to use it. Here's the code:
Dim myPara As Style
Dim myLastStyle As Style
Dim x As Long
Dim myTemplate As String
x = 1
myTemplate = "C:\Templates\Chatzros Kadshechu.dot"
Set myLastStyle = ActiveDocument.Styles("Ha'aros")
Set myPara = ActiveDocument.Styles("Parsha")
Do
Do
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Loop Until 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
work. What I'm trying to do is copy all the text between each heading (which
is tagged with a paragraph style named "Parsha") create a new document and
paste the text into the new document. Then loop it through all the headings.
Where I keep running into a problem is when it selects text that has more
than one style it gets confused with the Do Until statement. I think the
solution is to use the Range object, but I'm not familiar enough with it to
figure out how to use it. Here's the code:
Dim myPara As Style
Dim myLastStyle As Style
Dim x As Long
Dim myTemplate As String
x = 1
myTemplate = "C:\Templates\Chatzros Kadshechu.dot"
Set myLastStyle = ActiveDocument.Styles("Ha'aros")
Set myPara = ActiveDocument.Styles("Parsha")
Do
Do
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Loop Until 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