Here is the code I am using... breaks when it encounters tables :(
Sub CopyData()
Dim docSource As Document
Dim docDest As Document
Dim Paragraph As Paragraph
Dim tmpName As String
Set docSource = ActiveDocument
Set docDest = Documents.Add
For Each Paragraph In docSource.Paragraphs
docSource.Activate
If Paragraph.Style <> docSource.Styles(wdStyleHeading1) Then
Paragraph.Range.Select
Paragraph.Range.Copy
docDest.Activate
Selection.Paste
Selection.EndKey unit:=wdLine
End If
Next
Set docSource = Nothing
Set docDest = Nothing
End Sub
Hi,
I think you might be making this more difficult (and longer) than it needs
to be:
With Selection
.HomeKey Unit:=wdStory, Extend:=wdMove
With .Find
.ClearFormatting
.Text = ""
.Style = "Heading 1"
With .Replacement
.ClearFormatting
.Text = ""
End With
.Execute Replace:=wdReplaceAll
End With
End With
ActActiveDocument.SaveAs _
FileName:=ActiveDocument.Path & _
Replace(ActiveDocument.Name, ".doc", "_NoHeading1.doc")
This routine replaces any "Heading 1" formatted paragraph with ... nothing.
That is, it removes all the "Heading 1" paragraphs. The last line of the
routine saves the document
HTH,
Dave
> Here is the code I am using... breaks when it encounters tables :(
>
[quoted text clipped - 22 lines]
> Set docDest = Nothing
> End Sub
Jaypee - 25 Apr 2006 04:55 GMT
Thanks Dave, this is an elegant solution to the problem I originally portrayed.
Unfortunately, I did not elaborate the entire scenario I am dealing with....
I have one master document and several source documents.. for all comparison
purposes, they have the same number of Sections. Sections are differentiated
by the headers (having "Heading 1" style).
That is the reason I was using the paragraph style to lift out the
paragraphs in between -- the next step was to paste it in the corresponding
section.
Anyway, thanks... given the lack of context I provided, the solution you
gave was excellent.