2014-01-08 70 views
0

我已經使用Outlook 2010年成功地將下面的代碼:Outlook 2013中VBA代碼,而不是看着主動回覆電子郵件

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) 
    Dim myItem As MailItem 
    Set myItem = Application.ActiveInspector.CurrentItem 


    If InStr(1, myItem.Subject, "@gtd") > 0 Then 
     Dim objMe As Recipient 
     Set objMe = Item.Recipients.Add("[email protected]") 
     ' for testing only -- Set objMe = Item.Recipients.Add("[email protected]") 
     objMe.Type = olBCC 
     objMe.Resolve 
     Set objMe = Nothing 
    End If 
    Set myItem = Nothing 
End Sub 

Sub GTDTracking() 
    Dim initialSubj As String 
    Dim finalSubj As String 
    Dim myItem As MailItem 
    Set myItem = Application.ActiveInspector.CurrentItem 

    initialSubj = myItem.Subject 
    finalSubj = initialSubj & " (@gtd)" 
    myItem.Subject = finalSubj 
End Sub 

我最近切換到Outlook 2013年,提供打的答覆,並有新的回覆選項窗口停靠在消息列表中。不過,如果我的回答是這樣我的代碼失敗在這行:

Set myItem = Application.ActiveInspector.CurrentItem 

如果我打開通過雙擊該消息,因此沒有停放在郵件列表中,該代碼將運行得很好。

回答

4

這是我的工作。以下函數返回用戶正在查看的消息的Outlook.MailItem消息對象,無論它是停靠應答還是消息在其自己的窗口中。如果找不到打開的信息,則會返回Nothing。整個事情的關鍵是Application.ActiveExplorer.ActiveInlineResponse屬性,這是Outlook 2013中的新功能。如果您運行的是較舊版本的Outlook,則必須添加一些代碼才能避免嘗試調用ActiveInlineResponse

Function getActiveMessage() As Outlook.MailItem 

    Dim insp As Outlook.Inspector 

    If TypeOf Application.ActiveWindow Is Outlook.Inspector Then 
     Set insp = Application.ActiveWindow 
    End If 


    If insp Is Nothing Then 
     Dim inline as Object 
     Set inline = Application.ActiveExplorer.ActiveInlineResponse 
     If inline Is Nothing Then Exit Function 

     Set getActiveMessage = inline 
    Else 
     Set insp = Application.ActiveInspector 
     If insp.CurrentItem.Class = olMail Then 
      Set getActiveMessage = insp.CurrentItem 
     Else 
     Exit Function 
     End If 

    End If 

End Function 

讓我知道它是否適合您!

+0

完美的作品!好的解決方案 –

相關問題