I am facing a situation where I can use Word Editor to modify the contents of an open inbox(active开发者_StackOverflow中文版 explorer).
I know to use word editor for compose window, but is there a way to access the body of the email thorough word editor.
Code for using Word Editor in Compose Window.
public void Click(Office.IRibbonControl Control)
{
Outlook.Inspector uiInspector = Globals.ThisAddIn.Application.ActiveInspector();
object uiObject = uiInspector.CurrentItem;
if (uiObject is Outlook.MailItem && uiInspector.IsWordMail())
{
Outlook.MailItem uiItem = (Outlook.MailItem)uiObject;
Word.Document uiDoc = uiInspector.WordEditor as Word.Document;
if (uiDoc != null)
{
Word.Find uiFind = uiDoc.Range().Find;
uiFind.Text = "ASA^$^$^#^#^#^#^#";
while (uiFind.Execute())
{
var rng = uiFind.Parent as Microsoft.Office.Interop.Word.Range;
rng.Hyperlinks.Add(rng, "http://stack.com=" + rng.Text + "outlook2007");
rng.Collapse(Word.WdCollapseDirection.wdCollapseEnd);
}
}
}
May be it is too late to answer here, but it will help other developer who got into same problem as I was.
How to add word document text into Outlook compose email ?
let suppose you have a Word document some where in your directory and want to fill your compose email with the document text.
Here I just modified your Click event
using Microsoft.Office.Interop.Outlook;
using Microsoft.Office.Interop.Word;
public void Click(Office.IRibbonControl Control)
{
string documentPath = @"C:\\Documents";
Outlook.Inspector = OutlookApp.ActiveInspector();
Document we = inspector.WordEditor as Document;
Find wf = we.Range().Find;
wf.Application.Selection.Range.ImportFragment(documentPath);
}
精彩评论