delete all??

C

Cathy Finnegan

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
 
D

Doug Robbins

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
 

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