I am trying to set the reply-to address of outbound emails based on whether a particular address is in the “To” or “CC” field of the outbound message. I have gotten this far, only to stumble on “Object required” errors on the “Set myCounter…” line. Any assistance would be greatly appreciated:
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
Your error is on
because VB uses
Setto assign an object (a class), while you’re getting an integer!So you could change it into