简体   繁体   中英

set cursor position in Outlook AddIn using word editor range.select() new mail

My code:

 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)
        {

        }
    }

It is working for reply and forward to set the cursor position but i'm getting an exception like the screenshot below when new mail is selected. Anyone have any suggestion for getting rid of this error??

在此处输入图片说明

Word editor is not fully initialized by the time NewIsnpector is called. Wait for the Inspector.Activate event to fire. Keep in mind that it fires multiple times.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM