0
我想從Word 2010文檔中刪除註釋。無論我在哪裏找到不符合公司標準的字體,我都自己添加了它們。System.AccessViolationException在Word中Comment.Delete遞歸
但是每當我調用DeleteRecursively,我得到一個System.AccessViolationException。使用VBA刪除註釋運行沒有任何錯誤。對象方法不同,因爲在VBA中我有評論(i)。刪除而不是刪除。
我有一個產品版本14.0.7015.1000。
foreach (Word.Paragraph para in storyRange.Paragraphs)
{
if (Helper.ParagraphHasWrongFont(para))
{
Word.Range anchor = para.Range;
if (anchor.Comments.Count == 0)
{
Word.Comment comment = anchor.Comments.Add(anchor, "The font is wrong in this one.");
comment.Author = "System";
}
}
}
for (int i = ActiveDocument.Comments.Count - 1; i >= 1; i--)
{
if (ActiveDocument.Comments[i].Author == "System")
{
Word.Comment cmt = ActiveDocument.Comments[i];
cmt.DeleteRecursively();
}
}