Using Outlook VBA to forward Emails, but want exclude appointments

前端 未结 2 1247
暗喜
暗喜 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
    

提交回复
热议问题