I suspect you macro doesn't really "stop" -- it's just that you're pasting
the contents of pTarget into pTarget (in the original document), not into
the new document. You might be able to make it work with
ActiveDocument.Range.Paste
because the Documents.Add causes the second document to become the
ActiveDocument.
The second problem, which you haven't yet run into, has to do with using
"ActiveDocument" in a macro that deals with two or more documents. It just
isn't reliable -- you can never be sure which document is active at any
given point. Instead, declare Document objects and assign them as needed.
Like this:
Dim pH1 As Word.Range
Dim pH2 As Word.Range
Dim pTarget As Word.Range
Dim Doc1 As Word.Document, Doc2 As Word.Document
Set Doc1 = ActiveDocument ' at the time the macro starts
Set Doc2 = wrdApp.Documents.Add(DocumentType:=wdNewBlankDocument)
Set pH1 = Doc1.Range
' do the first Find
Set pH2 = Doc1.Range
' do the second Find
Set pTarget = Doc1.Range(Start:=pH1.End + 1, End:=pH2.Start - 1)
pTarget.Copy
Doc2.Range.Paste
Even better, you can avoid using Copy/Paste altogether, so if the user has
something on the clipboard it won't be wiped out. Replace the last two
statements with
Doc2.Range.FormattedText = pTarget.FormattedText

Signature
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
> Hi!
>
[quoted text clipped - 39 lines]
>
> Thanks in advance
FIRSTROUNDKO - 13 Jul 2007 16:45 GMT
Thanks for your help
I updated my code this, the error I now get is "object required"
Sub abcxyz()
Dim pH1 As Word.Range
Dim pH2 As Word.Range
Dim pTarget As Word.Range
Dim Doc1 As Word.Document
Dim Doc2 As Word.Document
Set Doc1 = ActiveDocument ' at the time the macro starts
Set Doc2 = wrdApp.Documents.Add(DocumentType:=wdNewBlankDocument)
Set pH1 = Doc1.Range
With pH1.Find
.ClearFormatting
.Text = "abc"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchWildcards = False
End With
Set pH2 = Doc1.Range
With pH2.Find
.ClearFormatting
.Text = "xyz"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchWildcards = False
End With
Set pTarget = Doc1.Range(Start:=pH1.End + 1, End:=pH2.Start - 1)
pTarget.Copy
Doc2.Range.Paste
End Sub
>I suspect you macro doesn't really "stop" -- it's just that you're pasting
>the contents of pTarget into pTarget (in the original document), not into
[quoted text clipped - 40 lines]
>>
>> Thanks in advance
Jay Freedman - 13 Jul 2007 17:06 GMT
Ah, I missed that in your first post: For each of the Find operations,
you've set the parameters but you never called the .Execute method. That
means both pH1 and pH2 remain the same as Doc1.Range. In fact, I got a
different error -- when the macro tried to assign pTarget, it got an "out of
range" error because pH1.End + 1 is past the end of the document.
In two places, after .MatchWildcards = False, add
.Execute

Signature
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
> Thanks for your help
>
[quoted text clipped - 84 lines]
>>>
>>> Thanks in advance
FIRSTROUNDKO - 13 Jul 2007 17:23 GMT
thanks, here is my solution
Sub abcxyz()
Dim pH1 As Word.Range
Dim pH2 As Word.Range
Dim pTarget As Word.Range
Dim Doc1 As Word.Document
Set Doc1 = ActiveDocument ' at the time the macro starts
Set pH1 = Doc1.Range
With pH1.Find
.ClearFormatting
.Text = "abc"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchWildcards = False
.Execute
End With
Set pH2 = Doc1.Range
With pH2.Find
.ClearFormatting
.Text = "xyz"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchWildcards = False
.Execute
End With
Set pTarget = Doc1.Range(Start:=pH1.End + 1, End:=pH2.Start - 1)
Word.Documents.Add
pTarget.Copy
ActiveDocument.Range.Paste
End Sub
>Ah, I missed that in your first post: For each of the Find operations,
>you've set the parameters but you never called the .Execute method. That
[quoted text clipped - 11 lines]
>>>>
>>>> Thanks in advance