vba 如何使用vba删除word文档的整行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24112398/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to remove the entire line of a word doc using vba
提问by Ben
The following line of code will insert text into a bookmark range in a word document.
以下代码行将文本插入到 Word 文档的书签范围内。
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?
如果我没有任何地址数据,如何删除包含地址书签的整行?
回答by dcromley
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
回答by Kazimierz Jawor
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