Sending ONLY Range or Page x, BUT not entire Activesheet, How ?
Hi Corey,
Ron,
Just found i am getting an error now due to the Sheet name.
What i need to reference is NOT BY Sheet NAME but by Active Sheet then
Range in that Sheet,
SEE Comments Below with Arrows.
If you follow Ron's link you will see that he has responded to your need to
mail a specified range in the body of an outlook email.
More specifically, Ron has today posted a revised procedure and an updated,
more flexible RangetoHTML function.
If you plug your specific data into Ron's new code, you will obtain the
following:
'=============
Public Sub Mail_Selection_Outlook_Body()
Dim sh As Worksheet
Dim rng As Range
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Set sh = ActiveSheet
Set rng = sh.Range("B45:J107")
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = sh.Range("B53").Value
.CC = sh.Range("E53").Value
.BCC = ""
.Subject = sh.Range("B55").Value
.HTMLBody = RangetoHTML(sh, rng)
.Display 'or use .Send
End With
Set OutMail = Nothing
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub
'---------------------
Public Function RangetoHTML(sh As Worksheet, rng As Range)
'Changed by Ron de Bruin 25-June-2006
' You can't use this function in Excel 97
Dim TempFile As String
Dim Nwb As Workbook
Dim fso As Object
Dim ts As Object
sh.Copy
Set Nwb = ActiveWorkbook
With Nwb.Sheets(1)
On Error Resume Next
.DrawingObjects.Visible = True
.DrawingObjects.Delete
On Error GoTo 0
End With
TempFile = Environ$("temp") & "/" & _
Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
With Nwb.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=TempFile, _
Sheet:=sh.Name, _
source:=rng.Address, _
HtmlType:=xlHtmlStatic)
.Publish (True)
End With
Nwb.Close False
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.ReadAll
ts.Close
Set ts = Nothing
Set fso = Nothing
Set Nwb = Nothing
Kill TempFile
End Function
'<<=============
Note that the above code should replace your problematic code.
Clearly, if the code works for you, you should thank Ron.
---
Regards,
Norman
|