Improved Code to email a saved .xlsx file

jamestomi

New Member
Joined
Jul 18, 2014
Messages
9
Please help, I want below code after saving the excel file to email it to specific address. I appreciate all your comments and help. Thanks.

Sub NextReq()
Range("J8").Value = Range("J8").Value + 1
Range("A4:D8,A11:D14,F4:H4,F6:H6,F8:H8,A16:I37,I40").ClearContents
End Sub

Sub SaveRequisitionWithNewName()
Dim NewFN As Variant
' Copy Invoice to a new workbook
ActiveSheet.Copy
NewFN = "C:\StoresReq" & Range("J8").Value & ".xlsx"
ActiveWorkbook.SaveAs NewFN, FileFormat:=xlOpenXMLWorkbook
Mail_workbook_Outlook_2
ActiveWorkbook.Close
NextReq
End Sub

Sub Mail_workbook_Outlook_2()
Dim NewFN As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim FileExtStr As String
Dim OutApp As Object
Dim OutMail As Object

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

TempFilePath = Environ$("temp") & "\"
TempFileName = "C:\StoresReq" & Range("J8").Value & ".xlsx" & " " & Format(Now, "dd-mmm-yyyy h:mm:ss")




Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.to = "james.tomi@lixm.co.mz"
.CC = ""
.BCC = ""
.Subject = "URGENT - Branch Stores Requisition"
.Body = "Please note requirements urgently needed on attached requisition"
.Attachments.Add TempFilePath & TempFileName & FileExtStr
.Send 'or use .Display
End With
On Error GoTo 0
End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,221,064
Messages
6,157,713
Members
451,434
Latest member
VanDookie

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top