Yan
Yan

Reputation: 43

How to delete a selected document.Comment

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

Answers (1)

Ria
Ria

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

Related Questions