How to Email from Excel with attachments if they exist



How to Email from Excel with attachments if they exist. Test if files exist before attaching them to emails. Send many attachments from one email. Send a list a group of attachments if they exist. Indicate whether the attachment was sent or not

code
Sub Send_email_fromexcel()
Dim edress 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, path2, path3 As String
Dim lastrow As Integer
Dim attachment, attachment2, attachment3 As String
Dim x As Integer

x = 2

Do While Sheet1.Cells(x, 1) (does not equal) “”

Set outlookapp = CreateObject(“Outlook.Application”)
Set outlookmailitem = outlookapp.createitem(0)
Set myAttachments = outlookmailitem.Attachments
path = “C:UsersBarbDocumentsstatements”
path2 = “C:UsersBarbDocumentsstatementscatalogue.pdf”
path3 = “C:UsersBarbDocumentsstatementsspecials.pdf”
edress = Sheet1.Cells(x, 3)

subj = Sheet1.Cells(x, 4)
fname = Sheet1.Cells(x, 1)
filename = Sheet1.Cells(x, 5)
attachment = path + filename

outlookmailitem.To = edress
outlookmailitem.cc = “”
outlookmailitem.bcc = “”
outlookmailitem.Subject = subj
outlookmailitem.body = fname & vbCrLf & “Please find your statement attached” & vbCrLf & “Best Regards”

If Dir(path2) = “” Then
Sheet1.Cells(x, 6) = “not sent”
GoTo nextattch
Else
attachment2 = path2
myAttachments.Add (attachment2)
Sheet1.Cells(x, 6) = “sent”
End If
nextattch:
If Dir(path3) = “” Then
Sheet1.Cells(x, 7) = “not sent”
GoTo ende
Else
attachment3 = path3
myAttachments.Add (attachment3)
Sheet1.Cells(x, 7) = ” sent”
End If

ende:

myAttachments.Add (attachment)
outlookmailitem.display
‘outlookmailitem.send

lastrow = lastrow + 1
edress = “”
x = x + 1

Loop

Set outlookapp = Nothing
Set outlookmailitem = Nothing

End Sub

For more help visit my website or email me at easyexcelanswers@gmail.com.

Contact me regarding customizing this template for your needs.

Excel one-on-one on-line training available. Email me to arrange.

I am able to provide online help on your computer at a reasonable rate.

Check out my next one-hour Excel Webinar

I use a Blue condensor Microphone to record my videos, here is the link

Check out Crowdcast for creating your webinars

If you need to buy Office 2019 follow

I use Tube Buddy to help promote my videos
Check them out

Follow me on Facebook

TWEET THIS VIDEO

Follow me on twitter
easyexcelanswers

IG @barbhendersonconsulting

You can help and generate a translation to you own language

*this description may contain affiliate links. When you click them, I may receive a small commission at no extra cost to you. I only recommend products and services that I’ve used or have experience with.

Watch more new videos about Excel Office | Synthesized by Mindovermetal English

5/5 - (1 bình chọn)

Bài viết liên quan

Theo dõi
Thông báo của
guest
1 Comment
Cũ nhất
Mới nhất Được bỏ phiếu nhiều nhất
Phản hồi nội tuyến
Xem tất cả bình luận
trish07tx

What if there is not a first attachment, how can i get it to skip and move on to the next statement?. I keep getting the myAttachments error. I'm sooooo close! LOL