【问题标题】:Outlook 2007 VBA Address ListsOutlook 2007 VBA 地址列表
【发布时间】:2012-04-10 14:41:43
【问题描述】:

我正在尝试根据特定地址是在出站邮件的“收件人”还是“抄送”字段中设置出站电子邮件的回复地址。我已经走到这一步,只是在“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

【问题讨论】:

  • 您是否检查过(使用调试器)oMyItemoMyItem.Recipients 都不为空(无)?
  • 是的,我实际上已经解决了这个问题(当您的回复出现时),现在有一个单独的问题我可以轻松解决。对于那些感兴趣的人,我删除了声明 myCounter 的行并将 for 循环更改为: For i = 1 To oMyItem.Recipients.Count

标签: vba outlook outlook-2007


【解决方案1】:

你的错误是在

Set myCounter = oMyItem.Recipients.Count

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

Dim myCounter As Integer

myCounter = oMyItem.Recipients.Count

【讨论】:

    【解决方案2】:

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

    替换

    Set myCounter = oMyItem.Recipients.Count 
    

    myCounter = oMyItem.Recipients.Count
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-02
      相关资源
      最近更新 更多