Hi,
So I am sending out emails using thunderbird.exe and I am trying to get the the email to copy and paste TPerf.Range("A1:H40") into the body of the email. So far, I have been successful in only sending out a blank email! Please help, my script is as follows:
So I am sending out emails using thunderbird.exe and I am trying to get the the email to copy and paste TPerf.Range("A1:H40") into the body of the email. So far, I have been successful in only sending out a blank email! Please help, my script is as follows:
Rich (BB code):
Sub CreateEmail()
Dim thund As String, email As String, cc As String, subj As String, body As Variant, TPerf As Worksheet, TMV As Workbook
Set TMV = Workbooks("Investments Market Value Email Macro.xlsm")
Set TPerf = TMV.Sheets("Intraday Performance")
TPerf.Range("A1:H40").Copy
# to create and send out the email
email = "1234@myemail.ca"
subj = "Investments Performance"
body = TPerf.Range("A1:H40")
thund = "C:\Program Files\Mozilla Thunderbird\thunderbird.exe" & _
" -compose " & """" & _
"to='" & email & "'," & _
"subject='" & subj & "'," & _
"body='" & body
Call Shell(thund, vbNormalFocus)
Application.Wait (Now + TimeValue("0:00:10"))
SendKeys "^{ENTER}", True
DoEvents
ActiveWorkbook.Save
End Sub
Function RangetoHTML(rngHTML)
#I created this function because I thought it would help me copy and paste the cells into the body of the email, but I couldn't get it to work.
Dim fso As Object, ts As Object, TempFile As String, TempWB As Workbook, Rng As Range, TPerf As Worksheet, TMV As Workbook
Set TMV = Workbooks("Investments Market Value Email Macro.xlsm")
Set TPerf = TMV.Sheets("Intraday Performance")
Set TempWB = Workbooks.Add(1)
TempFile = Environ$("temp") & "\" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
'' copy the range and create a new workbook to paste the data into
TPerf.Range("A1:H40").Copy
With TempWB.Sheets(1)
.Cells(1).PasteSpecial xlPasteFormats, , True, True
.Cells(1).Select
Application.CutCopyMode = False
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 rngHTML
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream
rngHTML = ts.readall
ts.Close
rngHTML = Replace(rngHTML, "align=center x:publishsource=", _
"align=left x:publishsource=")
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
Last edited by a moderator: