I am trying to write a VBA code to send auto email reminders from an excel sheet however I am getting some error. Below is the code:
Sub SendEmail()
Dim olapp As Outlook.Application
Set olapp = CreateObject("Outlook.Application")
Dim olmail As Outlook.MailItem
Set olmail = olapp.CreateItem(olMailItem)
Dim maildest As String
Dim i As Integer
For i = 2 To 5
maildest = ""
maildest = Cells(i, 5).Value
olmail.To = maildest
olmail.Subject = "is it running yet?"
olmail.Body = "A gentle reminder that XXX tasks are still pending"
olmail.Send
Next i
Range("A8").Select
Set olmail = Nothing
Set olapp = Nothing
End Sub
Could you kindly guide as to what is wrong with the code? The loop never functions.
When I click the debug option it highlights the line : "olmail.To = maildest"
The code is able to shoot mail just to the 1st address in the excel sheet. For some reason the loop is not running the cycle beyond counter 1. Any suggestions? Thanks
Dim olapp As Object
Set olapp = CreateObject("Outlook.Application")
Dim olmail As Object
Dim maildest As String
Dim i As Integer
For i = 2 To 5
Set olmail = olapp.CreateItem(0)
maildest = ""
maildest = Cells(i, 5).Value
olmail.To = maildest
olmail.Subject = "is it running yet?"
olmail.Body = "A gentle reminder that XXX tasks are still pending"
olmail.Send
Next i
On Error GoTo 0
Range("A8").Select
Set olmail = Nothing
Set olapp = Nothing
End Sub
Still shows the same error as mentioned above by me :
When I click the debug option it highlights the line : "olmail.To = maildest"