Ben
Ben

Reputation: 21695

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

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?

Upvotes: 1

Views: 18184

Answers (2)

dcromley
dcromley

Reputation: 1410

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

Upvotes: 3

Kazimierz Jawor
Kazimierz Jawor

Reputation: 19077

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

Upvotes: 2

Related Questions