I have a log file containing login information. Each line is a separate login.
What I need to do is delete every line in the document containing a specified string.

I've written a macro (see code below) which doesn't work very well. There has to be a better way to do this!!

Can someone tell me how to do this more efficiently or better??

Any help/or suggestions is greatly appreciated.

TIA,
cathy


~~~~~~~~~ code ~~~~~~~~
With Selection
.HomeKey Unit:=wdStory
With .Find
.ClearFormatting
.Text = "Login succeeded for user 'me'. Connection: Non-Trusted."
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With ' .find
End With ' selection

Do While Selection.Find.Execute
With Selection
.HomeKey Unit:=wdLine
.EndKey Unit:=wdLine, Extend:=wdExtend
.Delete Unit:=wdCharacter, Count:=1
.HomeKey Unit:=wdStory

With .Find
.ClearFormatting
.Text = "Login succeeded for user 'me'. Connection: Non-Trusted."
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With ' .find
End With ' selection
Loop 'do while

Re: delete all?? by Doug

Doug
Mon Aug 02 18:41:26 CDT 2004

Hi Cathy,

Use:

Dim rdelete As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="Login succeeded for user 'me'. Connection:
Non-Trusted.", MatchWildcards:=False, Wrap:=wdFindContinue, Forward:=True) =
True
Set rdelete = Selection.Paragraphs(1).Range
rdelete.Delete
Loop
End With


--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
"Cathy Finnegan" <> wrote in message
news:56btg0dr6f27qptv120es7qrj1m247d9d4@4ax.com...
>I have a log file containing login information. Each line is a separate
>login.
> What I need to do is delete every line in the document containing a
> specified string.
>
> I've written a macro (see code below) which doesn't work very well.
> There has to be a better way to do this!!
>
> Can someone tell me how to do this more efficiently or better??
>
> Any help/or suggestions is greatly appreciated.
>
> TIA,
> cathy
>
>
> ~~~~~~~~~ code ~~~~~~~~
> With Selection
> .HomeKey Unit:=wdStory
> With .Find
> .ClearFormatting
> .Text = "Login succeeded for user 'me'. Connection: Non-Trusted."
> .Replacement.Text = ""
> .Forward = True
> .Wrap = wdFindContinue
> .Format = False
> .MatchCase = False
> .MatchWholeWord = False
> .MatchWildcards = False
> .MatchSoundsLike = False
> .MatchAllWordForms = False
> End With ' .find
> End With ' selection
>
> Do While Selection.Find.Execute
> With Selection
> .HomeKey Unit:=wdLine
> .EndKey Unit:=wdLine, Extend:=wdExtend
> .Delete Unit:=wdCharacter, Count:=1
> .HomeKey Unit:=wdStory
>
> With .Find
> .ClearFormatting
> .Text = "Login succeeded for user 'me'. Connection:
> Non-Trusted."
> .Replacement.Text = ""
> .Forward = True
> .Wrap = wdFindContinue
> .Format = False
> .MatchCase = False
> .MatchWholeWord = False
> .MatchWildcards = False
> .MatchSoundsLike = False
> .MatchAllWordForms = False
> End With ' .find
> End With ' selection
> Loop 'do while
>