2011-05-13 5 views
15

Outlook 메시지에서 서명 아래에 선택 태그 라인을 추가/제거하는 addin a back을 작성했습니다. 이 추가 기능은 문제없이 작동합니다._MailAutoSig Bookmark missing (Outlook 2010)

두 번째 추가 기능에서 잠재적으로 그 아래에 정보를 추가해야하며 (선택적 서명이 있는지 여부에 관계없이) Word 편집기에서 _MailAutoSig 책갈피를 다시 참조해야합니다. 내가 겪고있는 문제는이 책갈피가 더 이상 나타나지 않는다는 것과 다른 다른 추가 기능의 책갈피가 아니라는 것입니다.

두 코드의 차이점 중 하나는 ItemSend에서 전달 된 개체에서 첫 번째 MailItem이 변환되는 반면 두 번째 ItemSend 이벤트는 전에 처리된다는 것입니다. 추가 기능 내 작업의 코드 여기

  Word.Document toMsg = msg.GetInspector.WordEditor as Word.Document; 

     foreach (Word.Bookmark b in toMsg.Bookmarks) 
      Debug.Print(b.ToString()); 

     Word.Range r_toMsg; 

     try 
     { 
      string oBookmark = "_MailAutoSig"; // Outlook internal bookmark for location of the e-mail signature` 
      object oBookmarkObj = oBookmark; 
      if (toMsg.Bookmarks.Exists(oBookmark) == true) 
       Debug.Print("sigbookmark"); 
      r_toMsg = toMsg.Bookmarks.get_Item(ref oBookmarkObj).Range; 
     } 
     catch 
     { 
      string oOffsiteBookmark = "OffsiteBookmark"; 
      object oOffsiteBookmarkObj = oOffsiteBookmark; 

      if (toMsg.Bookmarks.Exists(oOffsiteBookmark) == true) // if the custom bookmark exists, remove it 
       Debug.Print("offsite bookmark"); 
     } 
     finally 
     { 
      r_toMsg = toMsg.Range(missing,missing); 
     } 

과 :

void InsertOffsiteSig(Outlook.MailItem oMsg) 
{ 
    object oBookmarkName = "_MailAutoSig"; // Outlook internal bookmark for location of the e-mail signature 
    string oOffsiteBookmark = "OffsiteBookmark"; // bookmark to be created in Outlook for the Offsite tagline 
    object oOffsiteBookmarkObj = oOffsiteBookmark; 

    Word.Document SigDoc = oMsg.GetInspector.WordEditor as Word.Document; // edit the message using Word 

    string bf = oMsg.BodyFormat.ToString(); // determine the message body format (text, html, rtf) 

    // Go to the e-mail signature bookmark, then set the cursor to the very end of the range. 
    // This is where we will insert/remove our tagline, and the start of the new range of text 

    Word.Range r = SigDoc.Bookmarks.get_Item(ref oBookmarkName).Range; 
    object collapseEnd = Word.WdCollapseDirection.wdCollapseEnd; 

    r.Collapse(ref collapseEnd); 

    string[] taglines = GetRssItem(); // Get tagline information from the RSS XML file and place into an array 


    // Loop through the array and insert each line of text separated by a newline 

    foreach (string taglineText in taglines) 
     r.InsertAfter(taglineText + "\n"); 
    r.InsertAfter("\n"); 

    // Add formatting to HTML/RTF messages 

    if (bf != "olFormatPlain" && bf != "olFormatUnspecified") 
    { 
     SigDoc.Hyperlinks.Add(r, taglines[2]); // turn the link text into a hyperlink 
     r.Font.Underline = 0; // remove the hyperlink underline 
     r.Font.Color = Word.WdColor.wdColorGray45; // change all text to Gray45 
     r.Font.Size = 8; // Change the font size to 8 point 
     r.Font.Name = "Arial"; // Change the font to Arial 
    } 

    r.NoProofing = -1; // turn off spelling/grammar check for this range of text 

    object range1 = r; 
    SigDoc.Bookmarks.Add(oOffsiteBookmark, ref range1); // define this range as our custom bookmark 


    if (bf != "olFormatPlain" && bf != "olFormatUnspecified") 
    { 
     // Make the first line BOLD only for HTML/RTF messages 

     Word.Find f = r.Find; 
     f.Text = taglines[0]; 
     f.MatchWholeWord = true; 
     f.Execute(); 
     while (f.Found) 
     { 
      r.Font.Bold = -1; 
      f.Execute(); 
     } 
    } 
    else 
    { 
     // otherwise turn the plain text hyperlink into an active hyperlink 
     // this is done here instead of above due to the extra formatting needed for HTML/RTF text 

     Word.Find f = r.Find; 


     f.Text = taglines[2]; 
      f.MatchWholeWord = true; 
      f.Execute(); 
      SigDoc.Hyperlinks.Add(r, taglines[2]); 
     } 
     r.NoProofing = -1; // disable spelling/grammar checking on the updated range 
     r.Collapse(collapseEnd); 
} 

답변

4

문제는 마이크로 소프트가 "사무실 HTML로 변환한다는 것입니다 여기에

는 내가 현재 쓰고에서 코드입니다 "_MailAutoSig 책갈피가 사라지게하는 ItemSend() 이벤트를 발생시키기 전에 정상적인 HTML에 적절한 용어를 모르겠습니다.

_MailAutoSig 책갈피를 다시 얻는 유일한 방법은 ItemSend() 이벤트를 먼저 취소 한 다음 전자 메일 개체에 액세스하여 사용자가 원하는 방식으로 조작하고 사용자를 추가하는 기능을 실행하는 타이머를 시작하는 것입니다 이메일을 표시하는 속성이 처리 된 다음 이메일을 다시 보냅니다.

예를 들어

: 나는 내가 ItemSend() 이벤트에 때까지 일부 Outlook 필드가 설정되지 않은 프로젝트에 대한 비슷한 일을해야했다

 
Dim modItem As Object 'need to hold the item somewhere so the timer can access it 

Sub object_ItemSend(ByVal Item As Object, Cancel As Boolean) 
    If Item.UserProperties.Item("isModded") Is Nothing Then 
     'User has composed a mail and hit "Send", we need to make our modifications to the signature though 
     modItem = item 
     Cancel = True 'cancel the Send so we can make the modifications 
     mytimer.Enabled = True 'fire off a timer to make the modifications 
     Exit Sub 
    Else 
     Item.UserProperties.Item("isModded").Delete 'this flag will keep the email from ping-ponging between ItemSend and the timer 
    End If 
End Sub 

'10 millisecond timer? I think the cancel is almost instant, but experiment 
Sub mytimer_Timer() 
    mytimer.Enabled = False 
    If Not modItem Is Nothing Then 
     modItem.HtmlBody = ...... the signature bookmark will be intact again, so make your modifications ...... 
     modItem.UserProperties.Add("isModded", olText) 'no ping-pong 
     modItem.Send 'send it again 
     modItem = Nothing 
    End If 
End Sub 

, 내가 보낼 수있는 이메일을 강요하고, 수 내 정보를 입력 한 다음 보내기를 취소하십시오. 그것은 훌륭하게 작동했습니다.

이제이 코드는 내 머리 꼭대기에서 작성되었으므로 위의 코드가 완벽하지는 않지만 반드시 수행해야 할 작업에 대한 아이디어를 제공해야합니다.

+0

내 프로젝트의이 부분은 지금 과거이지만 코드는 훌륭합니다. 내가 C#으로 변환 할 시간을 찾으면 어떻게되는지 알려줄거야. –

+1

이것은 대부분을 C#으로 변환 할 수 있습니다. http://www.developerfusion.com/tools/convert/vb-to-csharp/ – Brain2000

+0

저는 그것을 사용했지만 항상 완벽하지는 않습니다. –