Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 1.14 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How do I get the selected text from a WordEditor Object (in Outlook2010) and Copy it to another Form?
  2. Outlook.MailItem mailItem;
  3. Outlook.Inspector inspector = mailItem.GetInspector;
  4.  
  5. // Obtain the Word.Document object from the Inspector object
  6. Word.Document document = (Word.Document)inspector.WordEditor;
  7.  
  8. // Copy the selected objects
  9. document.Application.Selection.Copy();
  10.        
  11. public void ShowEmail(string To, string Subject, string Body)
  12. {
  13.     Outlook.Application myOutlook = new Outlook.Application();
  14.     Outlook.NameSpace myNamespace = myOutlook.GetNamespace("MAPI");
  15.     myNamespace.Logon(null, null, null, null);
  16.     Outlook.MAPIFolder outbox = myNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox);
  17.     Outlook.MailItem mail = (Outlook.MailItem)outbox.Items.Add(Outlook.OlItemType.olMailItem);
  18.  
  19.     mail.Recipients.Add(To);
  20.     mail.Subject = Subject;
  21.     mail.Body = Body;
  22.  
  23.     mail.GetInspector.Activate();
  24. }
  25.  
  26. Go ahead and test it, create a button on your form and in the Click event handler:
  27.  
  28. private void button1_Click(object sender, EventArgs e)
  29. {
  30.     ShowEmail("youremailOutlookAddress.com", "Hello!", "Hey here's a test Email!");
  31. }