I am trying to send different texts through outlook using a macro in excel. I have the macro working to send one email, but when I try and loop to the second email address, I get a runtime error saying the item has been moved or deleted. I have the following code:
Sub sendText()
Dim aOutlook As Object
Dim aEmail As Object
Dim rngeAddresses As Range, rngeCell As Range, strRecipients As String
Set aOutlook = CreateObject("Outlook.Application")
Set aEmail = aOutlook.CreateItem(0)
'set sheet to find address for e-mails as I have several people to mail to
'Find how many people to email to
Dim x As Integer
x = Sheet1.Range("m2").Value
Set rngeAddresses = Sheet3.Range("L1:L" & x)
For Each rngeCell In rngeAddresses.Cells
strRecipients = strRecipients & ";" & rngeCell.Value
Next
'set Importance
aEmail.Importance = 2
'Set Subject
aEmail.Subject = ""
'Set Body for mail
Dim eText As Integer
Do
For eText = 1 To 16
Sheet3.Activate
Range("L" & eText).Select
If ActiveCell.Value <> "" Then
aEmail.Body = Sheet3.Range("J" & eText).Value
Else
Exit Do
End If
aEmail.To = rngeAddresses(1).Value
aEmail.Send
Next
Loop
'Set Recipient
'or send one off to 1 person use this static code
'aEmail.Recipients.Add "e-mail.address"
'Send Mail
End Sub
Any help would be great. Thanks.
p.s. I have commented out other methods I have tried that also did not work for sending separate emails.
Sub sendText()
Dim aOutlook As Object
Dim aEmail As Object
Dim rngeAddresses As Range, rngeCell As Range, strRecipients As String
Set aOutlook = CreateObject("Outlook.Application")
Set aEmail = aOutlook.CreateItem(0)
'set sheet to find address for e-mails as I have several people to mail to
'Find how many people to email to
Dim x As Integer
x = Sheet1.Range("m2").Value
Set rngeAddresses = Sheet3.Range("L1:L" & x)
For Each rngeCell In rngeAddresses.Cells
strRecipients = strRecipients & ";" & rngeCell.Value
Next
'set Importance
aEmail.Importance = 2
'Set Subject
aEmail.Subject = ""
'Set Body for mail
Dim eText As Integer
Do
For eText = 1 To 16
Sheet3.Activate
Range("L" & eText).Select
If ActiveCell.Value <> "" Then
aEmail.Body = Sheet3.Range("J" & eText).Value
Else
Exit Do
End If
aEmail.To = rngeAddresses(1).Value
aEmail.Send
Next
Loop
'Set Recipient
'or send one off to 1 person use this static code
'aEmail.Recipients.Add "e-mail.address"
'Send Mail
End Sub
Any help would be great. Thanks.
p.s. I have commented out other methods I have tried that also did not work for sending separate emails.
Last edited: