Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, i'm looking for a function to delete one line from a word document. I want to do this from VB.net.
I tried:
VB
Do While WordDoc.Content.Find.Execute(FindText:="%NP6%", Wrap:=Word.WdFindWrap.wdFindContinue) = True
           WordApp.Selection.Range.Bookmarks("\line").Range.Delete()
Loop

Instead of deleting one row it deletes the complete first part of the document, including the line with %NP6%.
Anyone an idea, Thanks, Rob
Posted
Updated 1-Jan-13 10:23am
v2

1 solution

What you're doing here is deleting lines while NP6% is still found in your document. Since you're deleting lines one by one it's no wonder all the lines up until the line with %NP6% are deleted. Once %NP6% is deleted the deleting will stop.
Instead you should try looping through the Sentences of WordDoc.Content and check the Text Property. If it contains %NP6% delete it.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 1-Jan-13 20:03pm    
Sound a right advice. My 5.

Happy New Year!
—SA
Sander Rossel 2-Jan-13 1:21am    
Thanks Sergey. And a happy new year to you too!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900