Click here to Skip to main content
14,767,302 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How do i copy the active email message selected text in outlook 2007 using, when the toolbar button is clicked bellow event is fired that event selected text to stored the sql server database how to write the code pls give me any suggestion , i am verify the link but that link <a href=""></a> is , i have code pls give me some idea

private void _objToolBarButton_Click(Office.CommandBarButton ctrl, ref bool cancel)

Thank u
Updated 6-Feb-12 1:55am

1 solution

private void savenumbers()
Outlook.Application oApp;
Outlook.Explorer oExp;
Outlook.Selection oSel;
object oItem;
long i;
// TODO: On Error GoTo Warning!!!: The statement is not translatable
oApp = new Outlook.Application();
oExp = oApp.ActiveExplorer();
oSel = oExp.Selection;
if ((oSel.Count == 0))
System.Windows.Forms.MessageBox.Show("Nothing selected");
for (i = 1; i <= oSel.Count; i++)
oItem = oSel[i];


catch (System.Exception ex)
System.Windows.Forms.MessageBox.Show("Error " + ex.Message.ToString());
public int outlooksavenumber(string testcopy)

int ReturnValue = 0;
ReturnValue = SqlHelper.ExecuteNonQuery(LITRMSConnection, "usp_Outlooksavenumbers",
new SqlParameter("@testcopy", testcopy));

return ReturnValue;

void DisplayMessage(object oItem)
//Outlook.MailItem oMailItem;
Outlook.MailItem oMail = (Outlook.MailItem)oItem;
string body = oMail.Body;
Outlook.Inspector inspector = oMail.GetInspector;

// Obtain the Word.Document object from the Inspector object
Microsoft.Office.Interop.Word.Document document = (Microsoft.Office.Interop.Word.Document)inspector.WordEditor;

// Copy the selected objects
string testcopy = "";
testcopy = document.Application.Selection.Text;


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900