I hope you are using Outlook, if yes use the following code, to send the range of cells.
Sub main_program ()
Range("a6:g36").Select ' This is the range you will include in the body of the email
Set source = Selection
On Error GoTo 0
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = WHATEVERYOUWANT@WHEREVERINTHEWORLD.COM
.CC = ""
.BCC = ""
.Subject = "Whatever you wnat to tell the user"
.HTMLBody = RangetoHTML
.Send 'or use .Display
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Function RangetoHTML()
Dim fso As Object
Dim ts As Object
Dim TempFile As String
TempFile = Environ$("temp") & "/" & _
Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
With ActiveWorkbook.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=TempFile, _
Sheet:=ActiveSheet.Name, _
source:=Selection.Address, _
HtmlType:=xlHtmlStatic)
.Publish (True)
End With
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.ReadAll
ts.Close
Set ts = Nothing
Set fso = Nothing
Kill TempFile
End Function
Hope this can help you
AWalle.
I hope you are using Outlook, if yes use the following code, to send the range of cells.
Sub main_program ()
Range("a6:g36").Select ' This is the range you will include in the body of the email
Set source = Selection
On Error GoTo 0
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = WHATEVERYOUWANT@WHEREVERINTHEWORLD.COM
.CC = ""
.BCC = ""
.Subject = "Whatever you wnat to tell the user"
.HTMLBody = RangetoHTML
.Send 'or use .Display
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Function RangetoHTML()
Dim fso As Object
Dim ts As Object
Dim TempFile As String
TempFile = Environ$("temp") & "/" & _
Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
With ActiveWorkbook.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=TempFile, _
Sheet:=ActiveSheet.Name, _
source:=Selection.Address, _
HtmlType:=xlHtmlStatic)
.Publish (True)
End With
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.ReadAll
ts.Close
Set ts = Nothing
Set fso = Nothing
Kill TempFile
End Function
Hope this can help you
AWalle.
Hi AWalle (sorry but i dont know your real name) is possible to use this code if the sheet where i select the range is hided?I hope you are using Outlook, if yes use the following code, to send the range of cells.
Sub main_program ()
Range("a6:g36").Select ' This is the range you will include in the body of the email
Set source = Selection
On Error GoTo 0
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = WHATEVERYOUWANT@WHEREVERINTHEWORLD.COM
.CC = ""
.BCC = ""
.Subject = "Whatever you wnat to tell the user"
.HTMLBody = RangetoHTML
.Send 'or use .Display
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Function RangetoHTML()
Dim fso As Object
Dim ts As Object
Dim TempFile As String
TempFile = Environ$("temp") & "/" & _
Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
With ActiveWorkbook.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=TempFile, _
Sheet:=ActiveSheet.Name, _
source:=Selection.Address, _
HtmlType:=xlHtmlStatic)
.Publish (True)
End With
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.ReadAll
ts.Close
Set ts = Nothing
Set fso = Nothing
Kill TempFile
End Function
Hope this can help you
AWalle.
Hi AWalle (sorry but i dont know your real name) is possible to use this code if the sheet where i select the range is hided?I hope you are using Outlook, if yes use the following code, to send the range of cells.
Sub main_program ()
Range("a6:g36").Select ' This is the range you will include in the body of the email
Set source = Selection
On Error GoTo 0
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = WHATEVERYOUWANT@WHEREVERINTHEWORLD.COM
.CC = ""
.BCC = ""
.Subject = "Whatever you wnat to tell the user"
.HTMLBody = RangetoHTML
.Send 'or use .Display
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Function RangetoHTML()
Dim fso As Object
Dim ts As Object
Dim TempFile As String
TempFile = Environ$("temp") & "/" & _
Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
With ActiveWorkbook.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=TempFile, _
Sheet:=ActiveSheet.Name, _
source:=Selection.Address, _
HtmlType:=xlHtmlStatic)
.Publish (True)
End With
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.ReadAll
ts.Close
Set ts = Nothing
Set fso = Nothing
Kill TempFile
End Function
Hope this can help you
AWalle.