Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

deleting repeating paragraph

Status
Not open for further replies.

kawnz

Technical User
Jan 30, 2003
67
0
0
US
I have a document that prints form letters telling the recipient of attached errors. The document then prints the errors following the form letter. I want to remove the form letters from the document and only print the errors.
I can remove the text from the letter, but cannot remove my company's address nor the client address from the document (it's hardcoded in the program that generates the letters).
Is there a way to have Word (or Excel) look for our company's name, and then delete the next 10 lines after that?
 

hi kawnz,

Yes. Word would be good for it with a little programming.
I'm assuming you can work with word vba

Deleting your company's address is as simple
as doing a find and replace (or delete rather).

Assuming the address doesn't change you can search for
the string containing the information. ie:

dim mysearch as range, strCompanyAddr as string
strCompanyAddr = "nonsense i don't need"

set mysearch = activedocument.content
mysearch.find.execute FindText:="strCompanyAddr"
if mysearch.find.found = true then
mysearch.select 'check it
mysearch.delete
else
msgbox "Yo dude! Address not found!"
end if

to delete the next ten lines:
dim pBegin As Range, pEnd As Range, pAllTen As Range

Set pBegin = Selection.Next(Unit:=wdParagraph, Count:=1)
pBegin.Select 'check it
Set pEnd = Selection.Next(Unit:=wdParagraph, Count:=10)
pEnd.Select 'check it

Set pAllTen = ActiveDocument.Range(pBegin.Start, pEnd.End)
pAllTen.Select 'check it
pAllTen.delete

The code assumes that you're deleting the next ten
line from where the insertion point (cursor) now
is, hence "Selection.Next"

I tested it. It works. You may, however, have to customize
it to fit your needs. NoTe: the code doesnt
compensate for errors. If there aren't 10 lines immediately
following the deletion of the Address, the code
will give you an error message at pEnd.Select.
Hope this helps.

Peace!
*****TYHAND
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top