Find lines and copy to document

P

p-e

Hi, folks

Does anyone have a macro laying around that does the following, I would
be most thankful if you would share it:
Two documents are active. One (A) consists of a list of words (separated
by ^p), one (B) is empty. I need to copy all the lines with a special
character (let's say a hyphen) from A to the other document. Must loop
until the whole document is searched.
 
H

Helmut Weber

Hi,

like this and in many other ways:

Sub Test67081()
Dim MyDocs(1 To 2) As Document
Set MyDocs(1) = Documents("Target.doc")
Set MyDocs(2) = Documents("Source.doc")
Dim rPrg As Paragraph
For Each rPrg In MyDocs(2).Paragraphs
If InStr(rPrg.Range.Text, "-") > 0 Then
MyDocs(1).Range.InsertAfter rPrg.Range.Text
End If
Next
End Sub

Note that there is no check,
whether target.doc is really empty,
and that the paragraphs in question
may contain more than one hyphen.
 
P

p-e

Helmut said:
Sub Test67081()
Dim MyDocs(1 To 2) As Document
Set MyDocs(1) = Documents("Target.doc")
Set MyDocs(2) = Documents("Source.doc")
Dim rPrg As Paragraph
For Each rPrg In MyDocs(2).Paragraphs
If InStr(rPrg.Range.Text, "-") > 0 Then
MyDocs(1).Range.InsertAfter rPrg.Range.Text
End If
Next
End Sub

Thanks! Great!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top