New Member
January 18, 2022
Hello
I try to modify this code - unfortunally without success
Target - send only a range from a1 to F5 via mail.
The attached program works fine - but sends the entire page.
Someone who can help ? Thanks in advance.
Sub save_and_send_sheet_via_outlook()
Dim xFile As String
Dim xFormat As Long
Dim Wb As Workbook
Dim Wb2 As Workbook
Dim FilePath As String
Dim FileName As String
Dim OutlookApp As Object
Dim OutlookMail As Object
On Error Resume Next
Application.ScreenUpdating = False
Set Wb = Application.ActiveWorkbook
ActiveSheet.Copy
Set Wb2 = Application.ActiveWorkbook
Select Case Wb.FileFormat
Case xlOpenXMLWorkbook:
xFile = ".xlsx"
xFormat = xlOpenXMLWorkbook
Case xlOpenXMLWorkbookMacroEnabled:
If Wb2.HasVBProject Then
xFile = ".xlsm"
xFormat = xlOpenXMLWorkbookMacroEnabled
Else
xFile = ".xlsx"
xFormat = xlOpenXMLWorkbook
End If
Case Excel8:
xFile = ".xls"
xFormat = Excel8
Case xlExcel12:
xFile = ".xlsb"
xFormat = xlExcel12
End Select
FilePath = Environ$("temp") & "\"
FileName = Wb.Name
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)
Wb2.SaveAs FilePath & FileName & xFile, FileFormat:=xFormat
With OutlookMail
.To = ".....@....com"
.CC = ""
.BCC = ""
.Subject = "REPORT" & Date
.Body = ""
.Attachments.Add Wb2.FullName
.Display
End With
Wb2.Close
Kill FilePath & FileName & xFile
Set OutlookMail = Nothing
Set OutlookApp = Nothing
Application.ScreenUpdating = True
End Sub
Trusted Members
Moderators
November 1, 2018
Have a look at Ron's code here: https://www.rondebruin.nl/win/.....amail4.htm
If you prefer to have the range as part of the message body, then have a look at this one instead: https://www.rondebruin.nl/win/.....bmail2.htm
1 Guest(s)