-
Runtime Error 424: Object not Defined
Hello,
I am new to Outlook VBA and am trying to write a code that will auto-reply to an e-mail when it comes in with a certain subject using a template I have created. I want this to run on all incoming messages. I have considered setting it up with a rule engine that runs my script and got it to work that way, but it didn't seem to meet all of my needs, so I wanted to try it without the rule engine. Below is what I have. I am getting an error that object is not defined. Thoughts:
Private Sub Application_Startup()
Dim Msg As Outlook.MailItem
Dim Ns As Outlook.NameSpace
Set Ns = Application.GetNamespace("MAPI")
Set Items = Ns.GetDefaultFolder(olFolderInbox).Items
Dim oRespond As Outlook.MailItem
End Sub
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
Dim arr() As String
Dim i As Integer
Dim m As MailItem
'On Error Resume Next
arr = Split(EntryIDCollection, ",")
For i = 0 To UBound(arr)
Set m = Application.Session.GetItemFromID(arr(i))
If m.Subject = "Test" Then
Set oRespond = Application.CreateItemFromTemplate("file path name here")
With oRespond
.Recipients.Add Item.SenderEmailAddress
.Subject = "Re: Referral Request - " & Item.Subject
.HTMLBody = oRespond.HTMLBody & vbCrLf & "--- original message attached ---" & vbCrLf & Item.HTMLBody & vbCrLf
.Attachments.Add Item
.Send
End With
End If
Set oRespond = Nothing
Next
End Sub
The error messages happens on this line:
.Recipients.Add Item.SenderEmailAddress
Thank you for your help!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules