Reputation: 43
There are a few comments in a Word document. After highlighting one, I'd like to delete it. I can loop through all comments. How to know which comment is selected? I wrote code below but document.Comments[i].Reference.Start
seems not really exist.
MSWord.Document document = ThisDocument.Instance.InteropDocument;
try
{
DocumentProtector.Unprotect(document);
for (int i=1; i<=document.Comments.Count; i++)
{
MSWord.Range r = document.Comments[i].Reference;
if (document.Application.Selection.Range.Start == document.Comments[i].Reference.Start)
document.Comments[i].Delete();
}
}
finally
{
DocumentProtector.Protect(document);
}
Upvotes: 0
Views: 591
Reputation: 10347
use Range.InRange
method:
Returns True if the range to which the method is applied is contained in the range specified by the Range argument.
Upvotes: 1