Can I find a string and delete whole line?

E

Ed

I have page numbers which must be deleted. They are all "(57 spaces)D -(1-4
numbers)". Can I do a search for the "(57 spaces)D -", then select the
whole line that string is on and delete it? ANd do it in a loop through the
whole document?

Thanks for all your help.
Ed
 
D

Doug Robbins - Word MVP

HI Ed,

The following code will do it:

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="[ ]{57}D -", MatchWildcards:=True,
Wrap:=wdFindContinue, Forward:=True) = True
Selection.Range.Bookmarks("\line").Range.Delete
Loop
End With

See the article “Finding and replacing characters using wildcards” at:

http://www.mvps.org/word/FAQs/General/UsingWildcards.htm

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
E

Ed

Thanks, Doug.

Ed

Doug Robbins - Word MVP said:
HI Ed,

The following code will do it:

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="[ ]{57}D -", MatchWildcards:=True,
Wrap:=wdFindContinue, Forward:=True) = True
Selection.Range.Bookmarks("\line").Range.Delete
Loop
End With

See the article "Finding and replacing characters using wildcards" at:

http://www.mvps.org/word/FAQs/General/UsingWildcards.htm

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
Ed said:
I have page numbers which must be deleted. They are all "(57 spaces)D -(1-4
numbers)". Can I do a search for the "(57 spaces)D -", then select the
whole line that string is on and delete it? ANd do it in a loop through the
whole document?

Thanks for all your help.
Ed
 

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