问题
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