Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default try to email with vba, but more than one sheet and convert to

You are welcome

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"pswanie" wrote in message ...
works like a charm.
i adjusted it to send 5 sheets in total.

(some of them are landscape and now shows as portrait. any easy way to get
to stay landscape)


thanx a million

"Ron de Bruin" wrote:

Before dinner


Try this for "Sheet1" and "Sheet2"

Sub Mail_Sheet_Outlook_Body()
' Don't forget to copy the function RangetoHTML in the module.
' Working in Office 2000-2007
Dim rng As Range
Dim rng2 As Range
Dim OutApp As Object
Dim OutMail As Object

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

Set rng = Sheets("Sheet1").UsedRange
Set rng2 = Sheets("Sheet2").UsedRange

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

On Error Resume Next
With OutMail
.To = "
.CC = ""
.BCC = ""
.Subject = "This is the Subject line"
.HTMLBody = RangetoHTML(rng) & "<br<br<br" & RangetoHTML(rng2)
.display 'or use .Display
End With
On Error GoTo 0

With Application
.EnableEvents = True
.ScreenUpdating = True
End With

Set OutMail = Nothing
Set OutApp = Nothing
End Sub


Function RangetoHTML(rng As Range)
' Changed by Ron de Bruin 28-Oct-2006
' Working in Office 2000-2007
Dim fso As Object
Dim ts As Object
Dim TempFile As String
Dim TempWB As Workbook

TempFile = Environ$("temp") & "/" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"

'Copy the range and create a new workbook to past the data in
rng.Copy
Set TempWB = Workbooks.Add(1)
With TempWB.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial xlPasteValues, , False, False
.Cells(1).PasteSpecial xlPasteFormats, , False, False
.Cells(1).Select
Application.CutCopyMode = False
On Error Resume Next
.DrawingObjects.Visible = True
.DrawingObjects.Delete
On Error GoTo 0
End With

'Publish the sheet to a htm file
With TempWB.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=TempFile, _
Sheet:=TempWB.Sheets(1).Name, _
Source:=TempWB.Sheets(1).UsedRange.Address, _
HtmlType:=xlHtmlStatic)
.Publish (True)
End With

'Read all data from the htm file into RangetoHTML
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.ReadAll
ts.Close
RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
"align=left x:publishsource=")

'Close TempWB
TempWB.Close savechanges:=False

'Delete the htm file we used in this function
Kill TempFile

Set ts = Nothing
Set fso = Nothing
Set TempWB = Nothing
End Function



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Ron de Bruin" wrote in message ...
Ok, I will post a example after dinner

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"pswanie" wrote in message ...
i would like to use the one where the sheet go in the body of the mail. but
i fail to see how to select more than one sheet. the examples that i see (and
i looked at the downloadeble workbooks) only add it as a new workbook. if i
uses kens thing i need to check and install that pdf on everymachine wich
could become a nightmare.

the perfect option would be to select more that one sheet and mail as
body.... or should i just have a next statement where it will mail 3 or 4
emails?

"Ron de Bruin" wrote:

For more sheets there are examples here
http://www.rondebruin.nl/sendmail.htm

For PDF see the link to Ken's site on this page
http://www.rondebruin.nl/pdf.htm


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"pswanie" wrote in message ...
2003

"Ron de Bruin" wrote:

Which Excel version ?

--



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert name into email address? [email protected] Excel Programming 3 December 12th 13 04:57 PM
send email to each customer email in excel sheet. -keevill- Excel Discussion (Misc queries) 3 July 17th 08 02:33 PM
How to convert Email into Mailto Email Addresses Sheikh Saadi Excel Worksheet Functions 2 April 12th 06 01:33 AM
convert for email Hank Hendrix Excel Programming 2 June 14th 04 03:16 AM


All times are GMT +1. The time now is 01:44 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"