Error Sending Emails with vba

Need a help trouble shooting my outlook vba code process (below)

Before I run this code I create a series of emails using Microsoft Mail merge

I run the process and it creates the emails (may as few as one email or hundreds of emails )

This is done with outlook enterprise offline

I the move the emails to a subfolder of the inbox and run the following code to add attachments and build in a delay if there are a lot of emails to send

At .send the macro stalls and give me an error message "Runtime error '-2147467259 (80004005): This method can't be used with an inline response mail item."

Sub a_Introduce_EPM_To_New_Clients()
    Dim mai As MailItem 'Object
    Dim acct As Long
    Dim Delay As Date, Start As Date, n As Integer
    Dim UpdtCount As Integer
    Dim FirstNm As String
    Dim AddAttachment As Integer
    Dim EmailsPerHour As Integer
    Dim FolderCheck As Integer, FolderName As String
    Dim EmailNo As Integer
    Dim ofldr As Object
    
    Dim AddAttachmentIntroEmail As Integer
        
    Dim recips As Outlook.Recipients
    Dim recip As Outlook.Recipient
    Dim pa As Outlook.propertyAccessor
    Const PR_SMTP_ADDRESS As String = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
    
    EmailNo = 1
   
    MsgBox "Select Email Folder"
    Set ofldr = Session.PickFolder

    AddAttachment = MsgBox("Do You Want to Add Listed Project Attachments", vbYesNo + vbDefaultButton2)
    AddAttachmentIntroEmail = MsgBox("Is this an Introduction Email?" & vbNewLine & vbNewLine & "Add Services Attachments?", vbYesNo + vbDefaultButton2)
'01-16-2018------------------
    If ofldr.Items.Count < 30 Then
        EmailsPerHour = InputBox("How Many Emails Per Hour do you want to send?" & vbNewLine & vbNewLine & "there are " & ofldr.Items.Count & " Emails in folder " & ofldr.Name, , ofldr.Items.Count)
    Else
        EmailsPerHour = InputBox("How Many Emails Per Hour do you want to send?" & vbNewLine & vbNewLine & "there are " & ofldr.Items.Count & " Emails in folder " & ofldr.Name, , 30)
    End If
'01-16-2018------------------
    Delay = Now() ' + 3 / 24 ' + 1 ' / 24
    n = 0
    Delay = DateAdd("n", 1, Delay) ' adds 5 minutes
    Start = Delay
    MsgBox Start
    UpdtCount = 0
    maiItem = 1 '01-18-2018
        Do While ofldr.Items.Count > 0
        
           Set mai = ofldr.Items(maiItem)
            If mai.Class = olMail Then
                With mai
                    
                    .Importance = olImportanceHigh
                    .ReadReceiptRequested = True
                    .OriginatorDeliveryReportRequested = True
                If AddAttachmentIntroEmail = 6 Then
                    .Attachments.Add "J:\Marketing\_Introduce EPM to New Clients\Typical CASp Services Available from EPM (Tailored).pdf"
                    .Attachments.Add "J:\Marketing\_Introduce EPM to New Clients\EPM Owners Representative - Project Manager 10-24-2014.pdf"
                    .Attachments.Add "J:\Marketing\_Introduce EPM to New Clients\Typical EPM Owner Rep - CM Menu of Services.pdf"
                ElseIf AddAttachment = 6 Then
'                    .Attachments.Add "J:\16 Jobs\16038 Sunset Center Water Damage\Construction Management\Bidding\Addenda\Trellis Addendum 01\16038 Sunset Water Damage Trellis Repair Addendum 01 01-30-2017 Combined Ref Info.pdf"
                End If
                    .DeferredDeliveryTime = Delay
            
                    UpdtCount = UpdtCount + 1
                    
                    If EmailsPerHour >= ofldr.Items.Count Then EmailsPerHour = ofldr.Items.Count
                    
                    If UpdtCount = EmailsPerHour Then
                        Delay = DateAdd("n", 60, Delay) ' adds 60 minutes
                        UpdtCount = 0
                        n = n + 1
                    End If
                    
On Error GoTo SendFail
                    .Send
SendFail:
'                    .Save
                End With
                
                EmailNo = EmailNo + 1
                UserForm1.TextBox1 = EmailNo & " UpdtCount  = " & UpdtCount
                UserForm1.TextBox2 = "Delay = " & Delay
                UserForm1.Show vbModeless
                DoEvents
            End If
            
    '++++++++++++++++++++++++++++===
    ''+++Sue Mosher   14-May-2003  17:45
    ''+++DeferredDeliveryTime takes a date/time value. (You can look these things up in Help -- in VBA,
    ''+++press F2 to get the object browser, select the property, then press F1.)
    ''+++You can use the DateAdd() function to add 15 minutes to the current date/time:
    ''+++dteThen = dateadd("n", 15, Now)
    ''+++objMail.DeferredDeliveryTime = dteThen
    '++++++++++++++++++++++++++++===
        
        
            Loop
    Unload UserForm1
        
    MsgBox "Start = " & Start & vbNewLine & "End = " & Delay
End Sub

Open in new window

rogerdjrAsked:
Who is Participating?
 
Martin LissOlder than dirtCommented:
It may not be the cause of your problem but 'maiItem' is not defined which points out that you should always have OPTION EXPLICIT at the top of you code.
0
 
NorieVBA ExpertCommented:
Where do you get the error?
0
 
rogerdjrAuthor Commented:
at the .send command
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
rogerdjrAuthor Commented:
Thanks for adding the tags - how can I do that for future questions?
0
 
Martin LissOlder than dirtCommented:
Select your code and then click the indicated icon.
Here's how.
0
 
rogerdjrAuthor Commented:
thanks
0
 
rogerdjrAuthor Commented:
Wow that fixed it!!! thanks
0
 
Martin LissOlder than dirtCommented:
Please don't forget to close the question.
0
 
Martin LissOlder than dirtCommented:
You’re welcome and I’m glad I was able to help.

If you expand the “Full Biography” section of my profile you’ll find links to some articles I’ve written that may interest you.

Marty - Microsoft MVP 2009 to 2017
              Experts Exchange MVE 2015
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2017
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.