我的代码:
public void inspectors_NewInspector(Inspector _Inspector)
{
try
{
if (_Inspector.CurrentItem is MailItem)
{
MailItem myMailItem = (MailItem)_Inspector.CurrentItem;
myMailItem.HTMLBody = "<html><table><tr><td>cursor</td></tr></table></html>";
Inspector insp = myMailItem.GetInspector;
insp.Activate();
Microsoft.Office.Interop.Word.Find uiFind = insp.WordEditor.Range().Find;
uiFind.Text = "cursor";
while (uiFind.Execute())
{
Microsoft.Office.Interop.Word.Range rng = uiFind.Parent;
rng.Select();
rng.Text = "";
break;
}
}
}
catch (System.Exception ex)
{
}
}
它正在用于回复和转发以设置光标位置,但是当我选择新邮件时,我会像下面的屏幕截图一样获得异常。任何人有任何建议摆脱这个错误?
答案 0 :(得分:0)
在调用NewIsnpector
时,Word编辑器尚未完全初始化。等待Inspector.Activate
事件触发。请记住,它会多次触发。