Hi,
I want to create macro, which will be sending email with attachments.
Because as a attachment I want to add just sheet with data (NOT WHOLE WORKBOOK), I copy the data to new workbook. But then I get error:
run-time error '-2147024894(80070002)':
cannot find this file. Verify the path and file name are correct.
I want to create macro, which will be sending email with attachments.
Code:
Sub create_email()
Dim wb1 As Workbook
Dim ws1 As Worksheet
Set wb1 = ActiveWorkbook
Set ws1 = wb1.Worksheets("row_data")
'******************************************************
'copy range
Dim wb_e As Workbook
Dim ws_e As Worksheet
Workbooks.Add
Set wb_e = ActiveWorkbook
Set ws_e = wb_e.Worksheets(1)
ws1.Columns("A:Z").Copy
ws_e.Paste
Application.CutCopyMode = False
'******************************************************
Dim Email_Subject, Email_Send_From, Email_Send_To, Email_Cc, Email_Bcc, Email_Body As String
Dim Mail_Object, Mail_Single As Variant
Email_Subject = ""
Email_Send_From = ""
Email_Send_To = ""
Email_Body = ""
Set Mail_Object = CreateObject("Outlook.Application")
Set Mail_Single = Mail_Object.CreateItem(0)
With Mail_Single
.Subject = Email_Subject
.To = Email_Send_To
.cc = Email_Cc
.Body = Email_Body
.HTMLBody = Email_Body
.Attachments.Add wb_e.FullName
.Display
End With
End Sub
Because as a attachment I want to add just sheet with data (NOT WHOLE WORKBOOK), I copy the data to new workbook. But then I get error:
run-time error '-2147024894(80070002)':
cannot find this file. Verify the path and file name are correct.