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

查看:25
本文介绍了使用 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?

谢谢,

迈克

推荐答案

只是一点点条件逻辑,以确保您只处理MailItem(因为objItem 是变体/对象,可能是另一种类型的项目,例如 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天全站免登陆