Using Outlook VBA to forward Emails, but want exclude appointments

前端 未结 2 1218
暗喜
暗喜 2021-01-16 20:05

I managed to find a nice little script that will forward emails to an external address becuase our exchange server is configured not to do that.

Private Sub          


        
相关标签:
2条回答
  • 2021-01-16 20:38

    Just a little bit of conditional logic to ensure that you're only dealing with MailItem (since objItem is variant/object and may be another type of item like an AppointmentItem, etc.):

    Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
    
        MsgBox "I'm working!", vbExclamation
    
        Dim varEntryIDs
        Dim objItem As Object
        Dim myItem As MailItem
        Dim i As Integer
        varEntryIDs = Split(EntryIDCollection, ",")
        For i = 0 To UBound(varEntryIDs)
            Set objItem = Application.Session.GetItemFromID(varEntryIDs(i))
    
            '## Check the item's TypeName and ONLY process if it's a MailItem:
    
            If TypeName(objItem) = "MailItem" Then
    
                Set myItem = objItem.Forward
                myItem.Recipients.Add "mike.dumka@outlook.com"
                myItem.Send
    
            Else:
                MsgBox "Type of item is: " & TypeName(objItem)
    
            End If
    
        Next
    End Sub
    
    0 讨论(0)
  • 2021-01-16 20:40

    You can either check the myItem.MessageClass property (it will be "IPM.Note" for the regular messages) or myItem.Class property - it will be 43 (olMail).

    0 讨论(0)
提交回复
热议问题