使用Outlook VBA转发电子邮件,但希望排除约会 [英] Using Outlook VBA to forward Emails, but want exclude appointments

查看:419
本文介绍了使用Outlook VBA转发电子邮件,但希望排除约会的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设法找到一个好的小脚本,将电子邮件转发到外部地址,因为我们的交换服务器被配置为不这样做。

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 Application_NewMailEx(ByVal EntryIDCollection As String)
    Dim varEntryIDs
    Dim objItem
    Dim i As Integer
    varEntryIDs = Split(EntryIDCollection, ",")
    For i = 0 To UBound(varEntryIDs)
        Set objItem = Application.Session.GetItemFromID(varEntryIDs(i))
        Set myItem = objItem.Forward
        myItem.Recipients.Add "mike.dumka@outlook.com"
        myItem.Send
    Next
End Sub



工作完美。但现在...我只想这样做,如果他们是消息,而不是约会更新或请求。我不知道在哪里找到,甚至找什么。我的VBA技能来自很久以前。

Works perfect. But now ... I would only like to do this if they are messages, not appointment updates or requests. I have no idea where to find this, or even what to look for. My VBA skills are from very long ago.

如果您查看截图,我想我以正确的方式使用MsgBox功能,但可以验证吗?

If you look at the screenshot, I think I have the MsgBox function in the right way, but could you verify?

谢谢,

Mike

推荐答案

只是一点条件逻辑,以确保您只处理 MailItem (因为 objItem 是variant / object,可能是另一个类型 $ c> AppointmentItem 等):

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

这篇关于使用Outlook VBA转发电子邮件,但希望排除约会的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆