下面的代码可以在Word文档中查找“Family”单词出现的次数,并对其进行选择和删除。虽然这段代码可以正常运行,但我想要查找所有被高亮显示的单词。
public void FindHighlightedText()
{
const string filePath = "D:\\COM16_Duke Energy.doc";
var word = new Microsoft.Office.Interop.Word.Application {Visible = true};
var doc = word.Documents.Open(filePath);
var range = doc.Range();
range.Find.ClearFormatting();
range.Find.Text = "Family";
while (range.Find.Execute())
{
range.Select();
range.Delete();
}
doc.Close();
word.Quit(true, Type.Missing, Type.Missing);
}