2012-04-10 8 views
-1

特定のアドレスが送信メッセージの "To"または "CC"フィールドにあるかどうかに基づいて、送信メールの返信先アドレスを設定しようとしています。私はこれまで、 "Set myCounter ..."行の "Object required"エラーでつまずくだけでした。どのような援助をいただければ幸いです:あなたは、整数を取得している間、VBは、オブジェクト(クラス)を割り当てるためにSetを使用しているためOutlook 2007のVBAアドレス一覧

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 = "[email protected]") Then 
     oMyItem.ReplyRecipients.Add "[email protected]" 
    End If 
Next i 
End Sub 
+0

Set myCounter = oMyItem.Recipients.Count 

を交換しますが、 'oMyItem'と' oMyItem.Recipients'両方が(何も)nullではないされていないこと(デバッガで)確認しましたか? – Marco

+0

はい、私は実際にそれを過ぎました(あなたの返信が現れたとき)、今は別の問題があり、私は簡単に解決できます。興味のある人は、myCounterを宣言している行を削除し、forループを次のように変更しました。For i = 1 To oMyItem.Recipients.Count – dmolavi

答えて

0

あなたのエラーが

Set myCounter = oMyItem.Recipients.Count 

にあります!
だから、Setの必要がないので、Integer型として宣言されています

Dim myCounter As Integer 

myCounter = oMyItem.Recipients.Count 
0

myCounterにそれを変更することができます。

myCounter = oMyItem.Recipients.Count 
関連する問題