Outlook VSTO TypeText("text")引发"TypeText方法或属性不可用,因为文档被锁定以进行编辑".例外 [英] Outlook VSTO TypeText("text") Throws "The TypeText method or property is not available because the document is locked for editing" Exception

查看:110
本文介绍了Outlook VSTO TypeText("text")引发"TypeText方法或属性不可用,因为文档被锁定以进行编辑".例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ActiveInspector WordEditor上调用TypeText("dummytext")会引发:

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

TypeText方法或属性不可用,因为文档被锁定以进行编辑.

这是我的代码:

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

推荐答案

如果以这种方式使用选择,我会看到很多问题.这就是我会做的

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

这篇关于Outlook VSTO TypeText("text")引发"TypeText方法或属性不可用,因为文档被锁定以进行编辑".例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆