Outlook VSTO TypeText("text") 抛出 "The TypeText method or property is not available because the document is locked for editing" 异常
Outlook VSTO TypeText("text") Throws "The TypeText method or property is not available because the document is locked for editing" Exception
在 ActiveInspector
上调用 TypeText("dummytext")
WordEditor 抛出:
TypeText 方法或 属性 不可用,因为文档已锁定以供编辑。
这是我的代码:
var inspector = myMailItem.GetInspector;
dynamic w = inspector.WordEditor;
dynamic wa = w.Application;
wa.Selection.TypeText("sometext");
如果以这种方式使用选择,我会遇到很多问题。我就是这样做的
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
在 ActiveInspector
上调用 TypeText("dummytext")
WordEditor 抛出:
TypeText 方法或 属性 不可用,因为文档已锁定以供编辑。
这是我的代码:
var inspector = myMailItem.GetInspector;
dynamic w = inspector.WordEditor;
dynamic wa = w.Application;
wa.Selection.TypeText("sometext");
如果以这种方式使用选择,我会遇到很多问题。我就是这样做的
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