Consulting

Results 1 to 3 of 3

Thread: Runtime Error 424: Object not Defined

  1. #1

    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!

  2. #2
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    There is no Item.

    There is m.

    If m.Subject = "Test" Then
    
        .Recipients.Add m.SenderEmailAddress
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

  3. #3
    Thank you! That makes sense and it worked perfectly! I appreciate your assistance with this!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •