I would like to be able to remove all lines from a Word document which
contain a specific text string and copy them to a second file at the same
time.

Can someone suggest some code that could do that?

I have seen similar posts in this forum which are close to my needs but none
that show me the code needed to both remove the entire line and append it to
a new file.

Thanks in advance
Al

Re: Macro to remove lines containing specific text by Graham

Graham
Tue May 06 23:16:48 PDT 2008

What is the string, and what do you mean by 'line'? A 'line' in Word is a
rather fluid concept the length of which is affected by a variety of
factors. Do you in fact mean 'paragraph'?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Al wrote:
> I would like to be able to remove all lines from a Word document which
> contain a specific text string and copy them to a second file at the
> same time.
>
> Can someone suggest some code that could do that?
>
> I have seen similar posts in this forum which are close to my needs
> but none that show me the code needed to both remove the entire line
> and append it to a new file.
>
> Thanks in advance
> Al



Re: Macro to remove lines containing specific text by Al

Al
Wed May 07 05:12:00 PDT 2008

By "string" I mean the same text will be found in each line
Each line can be considered a Paragraph
It is in fact a tabular list of hardware items but not in a Word table.
If that text is in the line then remove it from the file and build a second
file to store all the lines that are removed

You will end up with the original file minus those lines that contained the
text plus the second file which will contain all the removed lines

I hope that is clear and thank-you for taking the time to read my question.
Al



"Graham Mayor" wrote:

> What is the string, and what do you mean by 'line'? A 'line' in Word is a
> rather fluid concept the length of which is affected by a variety of
> factors. Do you in fact mean 'paragraph'?
>
> --
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor - Word MVP
>
> My web site www.gmayor.com
> Word MVP web site http://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>
>
> Al wrote:
> > I would like to be able to remove all lines from a Word document which
> > contain a specific text string and copy them to a second file at the
> > same time.
> >
> > Can someone suggest some code that could do that?
> >
> > I have seen similar posts in this forum which are close to my needs
> > but none that show me the code needed to both remove the entire line
> > and append it to a new file.
> >
> > Thanks in advance
> > Al
>
>
>

Re: Macro to remove lines containing specific text by Doug

Doug
Wed May 07 05:51:03 PDT 2008

Try this

Dim Source As Document, Target As Document
Dim Findthis As String
Findthis = InputBox("Enter the text to be found", "Finder")
Set Source = ActiveDocument
Set Target = Documents.Add
Source.Activate
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(Findtext:=Findthis, Forward:=True, _
MatchWildcards:=False, Wrap:=wdFindStop) = True
Set myrange = Selection.Paragraphs(1).Range
Target.Range.InsertAfter myrange & vbCr
myrange.Delete
Loop
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Al" <Al@discussions.microsoft.com> wrote in message
news:1977E76B-BFD0-47CD-8D45-D50EA03D0B61@microsoft.com...
> By "string" I mean the same text will be found in each line
> Each line can be considered a Paragraph
> It is in fact a tabular list of hardware items but not in a Word table.
> If that text is in the line then remove it from the file and build a
> second
> file to store all the lines that are removed
>
> You will end up with the original file minus those lines that contained
> the
> text plus the second file which will contain all the removed lines
>
> I hope that is clear and thank-you for taking the time to read my
> question.
> Al
>
>
>
> "Graham Mayor" wrote:
>
>> What is the string, and what do you mean by 'line'? A 'line' in Word is a
>> rather fluid concept the length of which is affected by a variety of
>> factors. Do you in fact mean 'paragraph'?
>>
>> --
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>> Graham Mayor - Word MVP
>>
>> My web site www.gmayor.com
>> Word MVP web site http://word.mvps.org
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>
>>
>> Al wrote:
>> > I would like to be able to remove all lines from a Word document which
>> > contain a specific text string and copy them to a second file at the
>> > same time.
>> >
>> > Can someone suggest some code that could do that?
>> >
>> > I have seen similar posts in this forum which are close to my needs
>> > but none that show me the code needed to both remove the entire line
>> > and append it to a new file.
>> >
>> > Thanks in advance
>> > Al
>>
>>
>>



Re: Macro to remove lines containing specific text by Al

Al
Wed May 07 10:30:04 PDT 2008

Thank-you very much Doug - that is absolutely what I needed.
Al

"Doug Robbins - Word MVP" wrote:

> Try this
>
> Dim Source As Document, Target As Document
> Dim Findthis As String
> Findthis = InputBox("Enter the text to be found", "Finder")
> Set Source = ActiveDocument
> Set Target = Documents.Add
> Source.Activate
> Selection.HomeKey wdStory
> Selection.Find.ClearFormatting
> With Selection.Find
> Do While .Execute(Findtext:=Findthis, Forward:=True, _
> MatchWildcards:=False, Wrap:=wdFindStop) = True
> Set myrange = Selection.Paragraphs(1).Range
> Target.Range.InsertAfter myrange & vbCr
> myrange.Delete
> Loop
> End With
>
>
> --
> Hope this helps.
>
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
>
> Doug Robbins - Word MVP
>
> "Al" <Al@discussions.microsoft.com> wrote in message
> news:1977E76B-BFD0-47CD-8D45-D50EA03D0B61@microsoft.com...
> > By "string" I mean the same text will be found in each line
> > Each line can be considered a Paragraph
> > It is in fact a tabular list of hardware items but not in a Word table.
> > If that text is in the line then remove it from the file and build a
> > second
> > file to store all the lines that are removed
> >
> > You will end up with the original file minus those lines that contained
> > the
> > text plus the second file which will contain all the removed lines
> >
> > I hope that is clear and thank-you for taking the time to read my
> > question.
> > Al
> >
> >
> >
> > "Graham Mayor" wrote:
> >
> >> What is the string, and what do you mean by 'line'? A 'line' in Word is a
> >> rather fluid concept the length of which is affected by a variety of
> >> factors. Do you in fact mean 'paragraph'?
> >>
> >> --
> >> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> >> Graham Mayor - Word MVP
> >>
> >> My web site www.gmayor.com
> >> Word MVP web site http://word.mvps.org
> >> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> >>
> >>
> >> Al wrote:
> >> > I would like to be able to remove all lines from a Word document which
> >> > contain a specific text string and copy them to a second file at the
> >> > same time.
> >> >
> >> > Can someone suggest some code that could do that?
> >> >
> >> > I have seen similar posts in this forum which are close to my needs
> >> > but none that show me the code needed to both remove the entire line
> >> > and append it to a new file.
> >> >
> >> > Thanks in advance
> >> > Al
> >>
> >>
> >>
>
>
>