My Code keeps stopping at the outlook display line

Answered My Code keeps stopping at the outlook display line

  • 2012년 8월 31일 금요일 오후 5:09
     
     

    I'm trying to get rich text box data to past into an outlook email.  I've created the following code, but the problem I'm having is that the code stops on outlook display doesn't continue.  I need it to continue in order to past the rich text data into the message window.  Does anyone know how I can get past this: 

                Outlook.Application olApp = new Outlook.Application();
                Outlook.MailItem olMsg = (Outlook.MailItem)olApp.CreateItem(Outlook.OlItemType.olMailItem);

                Clipboard.Clear();
                rtbFinal.SelectAll();
                rtbFinal.Copy();


                 olMsg.BodyFormat = Outlook.OlBodyFormat.olFormatRichText;
                 olMsg.Display(true);  - Code Stops Here 
                 SendKeys.SendWait("^(v)");

모든 응답

  • 2012년 9월 1일 토요일 오후 2:49
     
     

    I only see the copy

    rtbFinal.Copy();

    Where is the paste?

    chanmm


    chanmm

  • 2012년 9월 1일 토요일 오후 3:33
     
     

    Try this change:

    olMsg.Display( false ); 

  • 2012년 9월 2일 일요일 오전 1:07
     
      코드 있음

    I don't think it is necessarily your Outlook code that is causing an issue.  I removed 3 lines and just ran the Outlook piece, and it works without a problem for me.

                OL.Application olApp = new OL.Application();
                OL.MailItem olMsg = (OL.MailItem)olApp.CreateItem(OL.OlItemType.olMailItem);
                olMsg.BodyFormat = OL.OlBodyFormat.olFormatRichText;
                olMsg.Display(true);

  • 2012년 9월 4일 화요일 오후 2:03
     
     

     SendKeys.SendWait("^(v)");

    This is where I'm trying to paste into the outlook window.  I'm trying to paste rich text data with all the formatting and I tried pasting directly into the outlook window from the richtext box, but that didn't work.   And I didn't see the option to paste from the clipboard directly to the outlook window, so I'm trying to use sendkeys, but I keep getting an error.


    Kellie Murphy

  • 2012년 9월 4일 화요일 오후 2:20
     
     
    I tried that and the code no longer stops on the outlook display line, but I still can't get the richtext to paste into the window.  

    Kellie Murphy

  • 2012년 9월 4일 화요일 오후 3:11
     
     

    2 points:

    1. Please make sure that the "Copy" part works (for example: paste manually into the MailItem).

    2. If you aim for OL 2007\2010, you can use WordEditor in order to paste the data.
    Something like:

    using Microsoft.Office.Interop.Word;

    ....

    //<Copy something here>Inspector objInsp = Application.ActiveInspector;

    Document wDoc = objInsp.WordEditor as Document;
    Range wRange = wDoc.Range;
    wRange.Select();
    wRaneg.Paste();

    //<Release objects here>

  • 2012년 9월 4일 화요일 오후 4:13
     
     

    When I click on Ctrl V after the outlook window I can past my rich text data directly into the outlook message with no problem.  When I try it using the code: 

                                    

                Outlook.Applicatio

    n olApp = new Outlook.Applicat

    ion();
                Outlook.MailItem olMsg = (Outlook.MailItem)olApp.CreateItem(Outlook.OlItemType.olMailItem);

                Clipboard.Clear();
                rtbFinal.SelectAll();
                rtbFinal.Copy();


                 olMsg.BodyFormat = Outlook.OlBodyFormat.olFormatRichText;
                 olMsg.Display(false);


                 SendKeys.SendWait("^v");

    I get a message box that says: "Changes are not allowed while is running or if the option 'Break all processes when one process breaks is disabled'".   I think that the code is trying to paste the message in the C# code instead of the outlook window.  I just don't know how to get around this and make the message body of the outlook email have the focus.


    Kellie Murphy

  • 2012년 9월 4일 화요일 오후 4:57
     
     

    Please try the code I posted above (or a variation)

    (Document wDoc = objInsp.WordEditor as Document;
    Range wRange = wDoc.Range;
    wRange.Select();
    wRaneg.Paste();)

    Also, try to see if it works on Release, and not in Debug.
    Beware anyway that sendkeys might send the keys yo an unwanted window..

  • 2012년 9월 4일 화요일 오후 6:27
     
     

    Instead of simulating Paste, try setting the 'Body' or 'HTMLBody' property before calling 'Display':

        olMsg.Body = “My text”.



    • 편집됨 Viorel_MVP 2012년 9월 4일 화요일 오후 6:28
    •  
  • 2012년 9월 6일 목요일 오후 5:03
     
     
    I did that, but it shows I'm trying to paste from RichTextBox with the formatting and when I do that I get the RichText tags in the email.

    Kellie Murphy

  • 2012년 9월 10일 월요일 오전 3:09
    중재자
     
     답변됨 코드 있음

    Hi Kellie,

    Base on your issue, please try this code to transfer data from a RichTextBox control to an Outlook message

    Outlook.Application olApp = new Outlook.Application();
    Outlook.MailItem olMsg = (Outlook.MailItem)olApp.CreateItem(Outlook.OlItemType.olMailItem);
              
    Clipboard.Clear
    rtfFinal.SelStart = "0"
    rtfFinal.SelLength = Len(rtfData.Text)
    rtfData.SetFocus
                
    SendKeys "^c", True      'copy text
    Me.Hide
    olMsg.Display  'display Outlook message
    SendKeys "^v", True    ' paste text
    Me.Show
    

    Hope this can help you.

    Best Regards,


    Leo_Gao [MSFT]
    MSDN Community Support | Feedback to us

    • 답변으로 표시됨 Leo_GaoModerator 2012년 9월 17일 월요일 오전 1:18
    •