Excel 2010 VBA looping issue when sending emails

XfortunaX

New Member
Joined
Aug 28, 2014
Messages
28
The first email will send and the macro will continue to loop through (from watching the locals window it looks like everything is accurate) but nothing is sent after the first email. Here is the code:

Sub Mail_AMEX_Outlook()

Dim olApp As Outlook.Application
Dim olMail As Outlook.MailItem
Dim EmailBody As String
Dim NumNewAMEX As Integer
Dim X As Integer

Set olApp = CreateObject("Outlook.Application")
Set olMail = olApp.CreateItem(Outmailitem)

X = 2

NumNewAMEX = Application.CountA(Range("A:A"))

Do While X <= NumNewAMEX

EmployeeName = Cells(X, 1).Value
EmployeeEmail = Cells(X, 3).Value
FilePath = Cells(X, 4).Value
EmailBody = Cells(X, 5).Value
EmailBody = Replace(EmailBody, "Employeename", EmployeeName)
EmailBody = Replace(EmailBody, "Employeename", AMEXDate)

On Error Resume Next
With olMail
.To = EmployeeEmail
.CC = ""
.BCC = ""
.Subject = "AMEX Reconciliation: 06.14.2015"
.BodyFormat = olFormatHTML
.HTMLBody = EmailBody
.Attachments.Add FilePath
.SendUsingAccount = olApp.Session.Accounts.Item(2)
.Send 'or use .Display

End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing

X = X + 1
Loop

End Sub

Any help on this issue would be greatly appreciated.

Thank you,

Tuna
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top