vba – 在撰写电子邮件时,有没有办法获得收件人联系人类别?

我已将我的展望中的联系人分配到各种类别.所以我想创建一个规则,如果我向其中一个类别中的任何联系人发送电子邮件,则该电子邮件将被发送到电子邮件地址.

这是我目前拥有的代码,我不断收到错误438 for line Set oContact = oRecip.GetContact

Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim oContact As Outlook.ContactItem
    Dim oRecip
    Dim Recip As Recipient
    Dim BccRecip As String
    Dim strCategoryName As String



Set oRecipients = Item.Recipients
Set oRecipient = Recipients(1)

    Set oContact = oRecipient.GetContact

    strCategoryName = oContact.Categories


    strCategoryName = oContact.Categories

    If InStr(LCase(strCategoryName), "test") > 0 Then
        BccRecip = "abc@def.com"
    Else
        Exit Sub
    End If


    Set Recip = Item.Recipients.Add(BccRecip)
    Recip.Type = olBCC

    If Recip.Resolve Then
        Cancel = False
    Else
        Cancel = True
    End If
End Sub

在此先感谢您的帮助.

最佳答案 o代码中的Recip是收件人的集合.

你必须使用类似的东西

   Set oRecipients = Item.Recipients
   Set oRecipient = Recipients(1) 
点赞