Hey guys, what's up?
I'm with a little problem... I need to send a e-mail with different attachments to a huge list, so I decided to use a VBA program to make it easier. I'm using a code that I found in youtube (source: youtube.com/watch?v=0k8t2Fy6nSc), but it's giving me an error when finalizing the sending. I searched in the forum, but I didn't find anything that could help me to solve my error, so I'm here asking you for some help.
Here the code, and its error:
Sub Send_email_fromexcel()
Dim adress As String
Dim subj As String
Dim message As String
Dim filename As String
Dim outlookapp As Object
Dim outlookmailitem As Object
Dim myAttachments As Object
Dim path As String
Dim lastrow As Integer
Dim attachment As String
Dim x As Integer
x = 2
Do While Sheet1.Cells(x, 1) <> ""
Set outlookapp = CreateObject("Outlook.Application")
Set outlookmailitem = outlookapp.createitem(0)
Set myAttachments = outlookmailitem.Attachments
path = "C:\Users\Matheus.Marinello\Azul\"
adress = Sheet1.Cells(x, 1)
subj = Sheet1.Cells(x, 2)
filename = Sheet1.Cells(x, 3)
attachment = path + filename
outlookmailitem.To = adress
outlookmailitem.cc = ""
outlookmailitem.bcc = ""
outlookmailitem.Subject = subj
outlookmailitem.body = "Please find your statement attached" & vbCrLf & "Best Regards"
myAttachments.Add (attachment)
outlookmailitem.display
outlookmailitem.send '(error in this line)
lastrow = lastrow + 1
adress = ""
x = x + 1
Loop
Set outlookapp = Nothing
Set outlookmailitem = Nothing
End Sub
Thank you!
Bookmarks