Outlook VSTO TypeText(“text”) Throws “The TypeText method or property is not available because the document is locked for editing” Exception

一个人想着一个人 提交于 2019-12-11 05:38:33

问题


Calling TypeText("dummytext") on ActiveInspector WordEditor throws:

The TypeText method or property is not available because the document is locked for editing.

Here is my code:

var inspector = myMailItem.GetInspector;
dynamic w = inspector.WordEditor;
dynamic wa = w.Application;
wa.Selection.TypeText("sometext");


回答1:


I have seen lots of issues if using selection this way. This is how I would do it

object link = url;
object res = "url";
object missing = Type.Missing;

// get active inspector (note that this assumes you work always on the active email message).
var inspector = ThisAddIn.Application.ActiveInspector();
MailItem email = inspector.CurrentItem;  // get the email message 
Microsoft.Office.Interop.Word.Document document = email.GetInspector.WordEditor;
Microsoft.Office.Interop.Word.Selection sel = document.Windows[1].Selection;
doc.Hyperlinks.Add(sel.Range, ref res, ref missing, ref missing, ref link, ref missing);
sel.EndKey(Microsoft.Office.Interop.Word.WdUnits.wdLine);  // move to the end of selection
sel.InsertAfter("\n");  // insert new line
sel.MoveDown(Microsoft.Office.Interop.Word.WdUnits.wdLine);  // move one line down


来源:https://stackoverflow.com/questions/38964834/outlook-vsto-typetexttext-throws-the-typetext-method-or-property-is-not-ava

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!