B
bony_tony
Hi, I want to send emails through VBA in excel, from data in an excel
spreadsheet. The following code sends the first email fine, but when I
loop through to the next email, I get the error 'The item has been
moved or deleted' ...any ideas where i'm going wrong?
Sub Email_test()
Dim objOutlook As Outlook.Application
Dim objMessage As Outlook.MailItem
Dim company, i, cemail As String
Set objOutlook = CreateObject("Outlook.Application")
Set objMessage = objOutlook.CreateItem(olMailItem)
Range("B2").Select
Do Until ActiveCell = ""
company = ActiveCell
ActiveCell.Offset(0, 1).Range("A1").Select
i = ActiveCell
ActiveCell.Offset(0, 2).Range("A1").Select
cemail = ActiveCell
ActiveCell.Offset(1, -3).Range("A1").Select
With objMessage
.Recipients.Add cemail
.Recipients.ResolveAll
.Subject = company
.Body = "Your credit check reference for " & company & " is "
& i
End With
objMessage.Send
Loop
End Sub
Thanks people
spreadsheet. The following code sends the first email fine, but when I
loop through to the next email, I get the error 'The item has been
moved or deleted' ...any ideas where i'm going wrong?
Sub Email_test()
Dim objOutlook As Outlook.Application
Dim objMessage As Outlook.MailItem
Dim company, i, cemail As String
Set objOutlook = CreateObject("Outlook.Application")
Set objMessage = objOutlook.CreateItem(olMailItem)
Range("B2").Select
Do Until ActiveCell = ""
company = ActiveCell
ActiveCell.Offset(0, 1).Range("A1").Select
i = ActiveCell
ActiveCell.Offset(0, 2).Range("A1").Select
cemail = ActiveCell
ActiveCell.Offset(1, -3).Range("A1").Select
With objMessage
.Recipients.Add cemail
.Recipients.ResolveAll
.Subject = company
.Body = "Your credit check reference for " & company & " is "
& i
End With
objMessage.Send
Loop
End Sub
Thanks people