How to remove the entire line of a word doc using vba

為{幸葍}努か 提交于 2020-01-05 16:25:31

问题


The following line of code will insert text into a bookmark range in a word document.

objDoc.Bookmarks("DonorAddress").Range.Text = "6200 Main St."

How do I remove the entire line containing the address bookmark if I don't have any address data?


回答1:


By 'deleting the line' I believe you mean to 'delete paragraph'. If so you could do it in this way:

'2 steps to delete- rather not recommended
objDoc.Bookmarks("DonorAddress").Range.Paragraphs(1).Range.Select
Selection.Delete

or in one step:

objDoc.Bookmarks("DonorAddress").Range.Paragraphs(1).Range.Delete



回答2:


If 'deleting the line' means deleting just one line of a paragraph, the following is the way:

objDoc.Bookmarks("DonorAddress").Range.Paragraphs(1).Range.Select
Selection.HomeKey wdLine
Selection.EndKey wdLine, wdExtend
Selection.Delete


来源:https://stackoverflow.com/questions/24112398/how-to-remove-the-entire-line-of-a-word-doc-using-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!