floggingmolly
Board Regular
- Joined
- Sep 14, 2019
- Messages
- 167
- Office Version
- 365
- Platform
- Windows
I have a VBA code to generate emails based off data in the rows. It works as long as there are 2 or more rows of data. If there's only 1 row, it creates the first email but then keeps creating multiple empty emails and I have to force stop the code. Does anyone know how I can fix this issue? Below is the code I am using. Any help would be greatly appreciated.
Code:
Sub CreateMedalEmails()
Dim EApp As Object
Set EApp = CreateObject("Outlook.Application")
Dim EItem As Object
'Dim EApp As Outlook.Application
'Set EApp = New Outlook.Application
'Dim EItem As Outlook.MailItem
'Set EItem = EApp.CreateItem(olMailItem)
Dim RList As Range
Set RList = Range("A3", Range("A3").End(xlDown))
Dim R As Range
For Each R In RList
Set EItem = EApp.CreateItem(0)
With EItem
.To = R.Offset(0, 13)
.cc = R.Offset(0, 14)
.Subject = "Medals Monthly Guidance For " & R.Offset(0, 1) & ", " & R.Offset(0, 2)
.HTMLBody = "<b>" & R.Offset(0, 1) & "</b>" & " has a Current Classification of " & "<b>" & R.Offset(0, 8) & "</b>" & " and a Projected Classification of " & "<b>" & R.Offset(0, 9) & "</b>" & "." & " Leading indicators for this classification include:" & "<br>" & "<br>" _
& "<li>" & R.Offset(0, 10) & "</li>" _
& "<li>" & R.Offset(0, 11) & "</li>" _
& "<li>" & R.Offset(0, 12) & "</li>" _
& "<br>" & "<br>" & "<br>" _
& "<b>" & "Station Personnel Action Steps:" & "</b>" & "<br>" & "<br>" _
& "1. Access the SPRS (Keyword: MEDALS) the day you conduct the BD. Review the information pertaining to the SP and ensure you are providing the most current information (do not blindly rely on the indicators listed within this message)." & "<br>" & "<br>" _
& "2. Conduct the business discussion with the service provider." & "<br>" & "<br>" _
& "3. Enter the BD into CDAS as" & "<b>" & " Category & Type: " & "</b>" & "Business Outlook/Planning - Classification Review" & "<br>" & "<br>" & "<br>" & "<br>" _
& "Reference the " & "<font color = blue>" & "<a href =https://mysite.sharepoint.com/teams/ICA/OMF/Documents/BDS-130.pdf>" & "BDS-103 " & "</a>" & "</font>" & "for additional information, or the MEDALS SharePoint site - Keyword: MEDALS, or contact your BSM for assistance."
.Display
End With
Next R
Set EApp = Nothing
Set EItem = Nothing
End Sub