saloelrn1988
New Member
- Joined
- Apr 14, 2020
- Messages
- 32
- Office Version
- 365
- Platform
- Windows
Hi,
really need your advise
I'm trying to create a macro that creates an email with an attachment, however the code that I tried is giving me run time error please see below code:
Ps. the file that I tried to attached will vary depending on the month so I tried using some Cell that contains the folder and file name.
Sub Send_email()
'
' Send_email Macro
' Auto send email
'
' SET Outlook APPLICATION OBJECT.
Dim objOutlook As Object
Set objOutlook = CreateObject("Outlook.Application")
' CREATE EMAIL OBJECT.
Dim objEmail As Object
Dim pageEditor As Object
Dim xinspect As Object
Set objEmail = objOutlook.CreateItem(olMailItem)
With objEmail
.To = Worksheets("Email data").Range("B2")
.CC = Worksheets("Email data").Range("B3")
.Subject = Worksheets("Email data").Range("B4")
.body = Worksheets("Email data").Range("B5")
source_file = "C:\Users\reomon\Desktop\Accrual - OUS\" & Worksheets("Email data").Range("B6") & "\" & Worksheets("Email data").Range("B7")
.Attachments.Add source_file
.display
End With
' CLEAR.
Set objEmail = Nothing: Set objOutlook = Nothing
ErrHandler:
'
End Sub
really need your advise
I'm trying to create a macro that creates an email with an attachment, however the code that I tried is giving me run time error please see below code:
Ps. the file that I tried to attached will vary depending on the month so I tried using some Cell that contains the folder and file name.
Sub Send_email()
'
' Send_email Macro
' Auto send email
'
' SET Outlook APPLICATION OBJECT.
Dim objOutlook As Object
Set objOutlook = CreateObject("Outlook.Application")
' CREATE EMAIL OBJECT.
Dim objEmail As Object
Dim pageEditor As Object
Dim xinspect As Object
Set objEmail = objOutlook.CreateItem(olMailItem)
With objEmail
.To = Worksheets("Email data").Range("B2")
.CC = Worksheets("Email data").Range("B3")
.Subject = Worksheets("Email data").Range("B4")
.body = Worksheets("Email data").Range("B5")
source_file = "C:\Users\reomon\Desktop\Accrual - OUS\" & Worksheets("Email data").Range("B6") & "\" & Worksheets("Email data").Range("B7")
.Attachments.Add source_file
.display
End With
' CLEAR.
Set objEmail = Nothing: Set objOutlook = Nothing
ErrHandler:
'
End Sub