2011-04-19 61 views
1

我有以下類型的Outlook功能區:Microsoft.Outlook.Mail.Compose,Microsoft.Outlook.Mail.Read是否可以訪問Ribbon_Load上的當前MailItem?

我需要啓用或從該帶禁用的按鈕時,根據內容(正文)的郵件項目,我想在功能區的Load事件中執行此操作。

我有以下代碼,但ActiveInspector始終爲空。

private void RiverRaftRibbon_Load(object sender, RibbonUIEventArgs e) 
    { 
     var application = Globals.ThisAddIn.Application; 
     var inspector = application.ActiveInspector(); 
     MailItem myMailItem = (MailItem)inspector.CurrentItem; 

     string projectName; 
     DateTime? dueDate; 

     if (Common.ParserHelper.IsRiverRaftEmail(mail.HTMLBody, out projectName, out dueDate)) 
     { 
      btnAccept.Enabled = true; 
     } 
     else 
      btnAccept.Enabled = false; 

    } 

謝謝!

回答

2

試試這個:

var application = Globals.ThisAddIn.Application; 
Outlook.Selection selection = application.ActiveExplorer().Selection; 
        mailItem = selection[1] as Outlook.MailItem; 
相關問題