delete text in word document if bookmark is empty

Viewed 71

I have the following in a word document

"We are enclosing our office cheque bearing No [chqr] for Rs[chqra]/-(Rupees[chqral] only) drawn in favour of TOM representing registration cost for the above-mentioned charge instrument and a cheque bearing No [chqr2] for Rs [chgrmat2}(Rupees [amtw] only} drawn in your favour representing your fees"

[] are bookmarks in the word document.

My VBA codes are as follows:-

With objDoc
   If.Bookmarks.Exists(TagName).Then
   Set BkMkRng =.Bookmarks(TagName).Range
    BkMkRng.Text =TagValue
End if

VBA will fill all the bookmarks if exists in the above word document.

I would like to use a condition if Range K3= N then delete the following:-

"cheque bearing No [chqr2] for Rs [chgrmat2}(Rupees [amtw] only} drawn in your favour representing your fees" from the word document.

Your help will be highly appreciated

thanks

1 Answers
If Range("K3").Value="N" Then TagValue = ""
With objDoc
   If.Bookmarks.Exists(TagName).Then
   Set BkMkRng =.Bookmarks(TagName).Range
    BkMkRng.Text = TagValue
End if

where TagName is a bookmark referring to the range to be deleted.

Related