Outlook 2007 VBA地址列表

时间:2012-04-10 14:41:43

标签: vba outlook-2007 outlook-vba

我正在尝试根据特定地址是否在出站邮件的“收件人”或“抄送”字段中设置出站电子邮件的回复地址。我已经走到这一步,只是偶然发现了“Set myCounter ...”行中的“Object required”错误。任何帮助将不胜感激:

Option Explicit

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim oMyItem As Outlook.MailItem
Dim i As Integer
Dim AddressEntry As AddressEntry
Dim myCounter As Integer
Set oMyItem = Item
Set myCounter = oMyItem.Recipients.Count

For i = 1 To myCounter
    Set AddressEntry = oMyItem.Recipients(i).AddressEntry
    If (AddressEntry = "someuser@someaddress") Then
        oMyItem.ReplyRecipients.Add "replytouser@someaddress"
    End If
Next i
End Sub

2 个答案:

答案 0 :(得分:0)

您的错误已开启

Set myCounter = oMyItem.Recipients.Count

因为VB使用Set来分配一个对象(一个类),而你得到一个整数! 所以你可以把它改成

Dim myCounter As Integer

myCounter = oMyItem.Recipients.Count

答案 1 :(得分:0)

myCounter已被声明为整数,因此不需要Set

替换

Set myCounter = oMyItem.Recipients.Count 

myCounter = oMyItem.Recipients.Count