12 January 2017
Having made Richard’s changes in the application that launches the email correctly, the HTMLbodyas produced by the final line
LEEMail.HTMLBody = LEEMail.HTMLBody & "<br<B>Embedded Image:</B<br>" & "<imgsrc='" & LEEEmbed & "'" & " width='500' height='200'<br>" & "<br>Best Regards, <brSumit</font</span>"
which refers to the embedded file rather than 'cid:image.jpg as in Richard’s text. (below I use Richard’s exact text with a slightly different but still problematic result)
is
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META NAME="Generator" CONTENT="MS Exchange Server version rmj.rmm.rup.rpr">
<TITLE</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->
<P<FONT FACE="Calibri">This is a test of LaunchEmail putting the imageC:\Users\dbarton\Pictures\LOGOUBANK.JPG at default position dimensions width 500 , height 200</FONT</P>
</BODY>
</HTML<br<B>Embedded Image:</B<brimgsrc='C:\Users\dbarton\Pictures\LOGOUBANK.JPG' width='500' height='200'<brbr>Best Regards, <brSumit</font</span>
This is a screen shot of the email display before I sent it
When I send the email, what I get in my inbox is as below
I have confirmed that the file is correctly attached, even if not embedded.
This is the screen shot of the file from the attachment.
This is the source code of the email I received
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m=" xmlns=" http-equiv=Content-Type content="text/html; charset=us-ascii"<meta name=Generator content="Microsoft Word 15 (filtered medium)"<!--[if !mso]<style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style<![endif]--<style<!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
p
{mso-style-priority:99;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
span.EmailStyle18
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--</style<!--[if gtemso 9]<xml>
o:shapedefaults v:ext="edit" spidmax="1027" />
</xml<![endif]--<!--[if gtemso 9]<xml>
o:shapelayout v:ext="edit">
o:idmap v:ext="edit" data="1" />
</o:shapelayout</xml<![endif]--</head<body lang=EN-AU link="#0563C1" vlink="#954F72"<div class=WordSection1<p<span style='font-family:"Calibri",sans-serif'>This is a test of LaunchEmail putting the imageC:\Users\dbarton\Pictures\LOGOUBANK.JPG at default position dimensions width 500 , height 200</span<o:p</o:p</p<p class=MsoNormalbr<b>Embedded Image:</b<br<!--[if gtevml 1]<v:shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f">
v:strokejoinstyle="miter" />
v:formulas
v:feqn="if lineDrawnpixelLineWidth 0" />
v:feqn="sum @0 1 0" />
v:feqn="sum 0 0 @1" />
v:feqn="prod @2 1 2" />
v:feqn="prod @3 21600 pixelWidth" />
v:feqn="prod @3 21600 pixelHeight" />
v:feqn="sum @0 0 1" />
v:feqn="prod @6 1 2" />
v:feqn="prod @7 21600 pixelWidth" />
v:feqn="sum @8 21600 0" />
v:feqn="prod @7 21600 pixelHeight" />
v:feqn="sum @10 21600 0" />
</v:formulas
v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect" />
o:lock v:ext="edit" aspectratio="t" />
</v:shapetypev:shape id="AutoShape_x0020_1" o:spid="_x0000_s1026" type="#_x0000_t75" style='width:375pt;height:150pt;visibility:visible;mso-left-percent:-10001;mso-top-percent:-10001;mso-position-horizontal:absolute;mso-position-horizontal-relative:char;mso-position-vertical:absolute;mso-position-vertical-relative:line;mso-left-percent:-10001;mso-top-percent:-10001'>
w:wrap type="none"/>
w:anchorlock/>
</v:shape<![endif]--<![if !vml]<img width=500 height=200 src="cid:E6FBB0" v:shapes="AutoShape_x0020_1"<![endif]<br<br>Best Regards, <brSumito:p</o:p</p</div</body</html>
When I use Richard’s exact code,
LEEMail.HTMLBody = LEEMail.HTMLBody & "<br<B>Embedded Image:</B<br>" & "<imgsrc='cid:image.jpg'"LEEEmbed & "'" & " width='500' height='200'<br>" & "<br>Best Regards, <brSumit</font</span>"
I see this
,
When I send an ordinary test email, i see
And the source code looks like
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m=" xmlns=" http-equiv=Content-Type content="text/html; charset=us-ascii"<meta name=Generator content="Microsoft Word 15 (filtered medium)"<!--[if !mso]<style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style<![endif]--<style<!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--</style<!--[if gtemso 9]<xml>
o:shapedefaults v:ext="edit" spidmax="1026" />
</xml<![endif]--<!--[if gtemso 9]<xml>
o:shapelayout v:ext="edit">
o:idmap v:ext="edit" data="1" />
</o:shapelayout</xml<![endif]--</head<body lang=EN-AU link="#0563C1" vlink="#954F72"<div class=WordSection1<p class=MsoNormal>ASDFG<o:p</o:p</p<p class=MsoNormalo:pnbsp;</o:p</p<p class=MsoNormal<span style='font-size:12.0pt;font-family:"Times New Roman",serif;mso-fareast-language:EN-AU' <o:p</o:p</span</p<table class=MsoNormalTable border=0 cellpadding=0 width="100%" style='width:100.0%'<tr<td width="8%" rowspan=4 style='width:8.1%;padding:.75pt .75pt .75pt .75pt'<p class=MsoNormal style='line-height:105%'<span style='mso-fareast-language:EN-AU'<img width=59 height=83 id="Picture_x0020_4" src="cid:5812A0" alt="201506 Dennis Barton"</span<span style='font-size:12.0pt;line-height:105%;font-family:"Times New Roman",serif;mso-fareast-language:EN-AU'<o:p</o:p</span</p</td<td width="15%" style='width:15.18%;padding:.75pt .75pt .75pt .75pt'<p class=MsoNormal style='line-height:105%'<b<span style='font-size:7.5pt;line-height:105%;font-family:"Times New Roman",serif;color:maroon;mso-fareast-language:EN-AU'>Dennis Barton Director</span</b<span style='font-size:12.0pt;line-height:105%;font-family:"Times New Roman",serif;mso-fareast-language:EN-AU'<o:p</o:p</span</p</td<td width="25%" style='width:25.32%;padding:.75pt .75pt .75pt .75pt'<p class=MsoNormal align=right style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-align:right;line-height:105%'<b<span style='font-size:7.5pt;line-height:105%;font-family:"Times New Roman",serif;color:maroon'>Level 8 251 Adelaide Terrace Perth Western Australia</span</b<span style='font-size:12.0pt;line-height:105%;font-family:"Times New Roman",serif'<o:p</o:p</span</p</td<td width="10%" rowspan=4 style='width:10.12%;padding:.75pt .75pt .75pt .75pt'<p class=MsoNormal align=center style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-align:center;line-height:105%'<span style='font-size:12.0pt;line-height:105%;font-family:"Times New Roman",serif;mso-fareast-language:EN-AU'<img width=59 height=63 id="Picture_x0020_2" src="cid:92EDE0"</span<span style='font-size:12.0pt;line-height:105%;font-family:"Times New Roman",serif'<o:p</o:p</span</p</td<td width="40%" style='width:40.5%;padding:.75pt .75pt .75pt .75pt'<p class=MsoNormal align=right style='text-align:right;line-height:105%'<b<span style='font-size:18.0pt;line-height:105%;font-family:"Times New Roman",serif;color:maroon;mso-fareast-language:EN-AU'>Barton Consultancy</span</b<span style='font-size:18.0pt;line-height:105%;font-family:"Times New Roman",serif;color:#256109;mso-fareast-language:EN-AU'> </span<b<span style='font-size:10.0pt;line-height:105%;font-family:"Times New Roman",serif;color:#882124;mso-fareast-language:EN-AU'>Pty Ltd </span</b<span style='font-size:12.0pt;line-height:105%;font-family:"Times New Roman",serif;mso-fareast-language:EN-AU'<o:p</o:p</span</p</td</tr<tr<td width="15%" style='width:15.18%;padding:.75pt .75pt .75pt .75pt'<p class=MsoNormal style='line-height:105%'<b<span style='font-size:7.5pt;line-height:105%;font-family:"Times New Roman",serif;color:maroon;mso-fareast-language:EN-AU'>+61 417 937 854</span</b<span style='font-size:12.0pt;line-height:105%;font-family:"Times New Roman",serif;mso-fareast-language:EN-AU'<o:p</o:p</span</p</td<td width="25%" style='width:25.32%;padding:.75pt .75pt .75pt .75pt'<p class=MsoNormal align=right style='text-align:right;line-height:105%'<b<span style='font-size:7.5pt;line-height:105%;font-family:"Times New Roman",serif;color:maroon;mso-fareast-language:EN-AU'>PO Box 3584 East Perth 6892</span</b<span style='font-size:12.0pt;line-height:105%;font-family:"Times New Roman",serif;mso-fareast-language:EN-AU'<o:p</o:p</span</p</td<td width="40%" rowspan=2 style='width:40.5%;padding:.75pt .75pt .75pt .75pt'<p class=MsoNormal align=right style='text-align:right;line-height:105%'<b<span style='font-size:12.0pt;line-height:105%;font-family:"Times New Roman",serif;color:maroon;mso-fareast-language:EN-AU'>Providing solutions as actuaries, economists, mediators and statisticians.</span</b<span style='font-size:12.0pt;line-height:105%;font-family:"Times New Roman",serif;mso-fareast-language:EN-AU'<o:p</o:p</span</p</td</tr<tr style='height:9.75pt'<td width="15%" style='width:15.18%;padding:.75pt .75pt .75pt .75pt;height:9.75pt'<p class=MsoNormal style='line-height:105%'<b<span style='font-size:7.5pt;line-height:105%;font-family:"Times New Roman",serif;color:maroon;mso-fareast-language:EN-AU'>Skype Dennis.Barton.Work</span</b<span style='font-size:12.0pt;line-height:105%;font-family:"Times New Roman",serif;mso-fareast-language:EN-AU'<o:p</o:p</span</p</td<td width="25%" style='width:25.32%;padding:.75pt .75pt .75pt .75pt;height:9.75pt'<p class=MsoNormal align=right style='text-align:right;line-height:105%'<b<span style='font-size:7.5pt;line-height:105%;font-family:"Times New Roman",serif;color:maroon;mso-fareast-language:EN-AU'>Telephone +61 8 9225 5899 Facsimile + 61 8 9225 5877</span</b<span style='font-size:12.0pt;line-height:105%;font-family:"Times New Roman",serif;mso-fareast-language:EN-AU'<o:p</o:p</span</p</td</tr<tr style='height:9.75pt'<td width="15%" style='width:15.18%;padding:.75pt .75pt .75pt .75pt;height:9.75pt'<p class=MsoNormal style='line-height:105%'<span style='mso-fareast-language:EN-AU'<a href="mailto:"<b<span style='font-size:7.5pt;line-height:105%;font-family:"Times New Roman",serif;color:black'></span</b</a</span<span style='font-size:12.0pt;line-height:105%;font-family:"Times New Roman",serif;mso-fareast-language:EN-AU'<o:p</o:p</span</p</td<td width="25%" style='width:25.32%;padding:.75pt .75pt .75pt .75pt;height:9.75pt'<p class=MsoNormal align=right style='text-align:right;line-height:105%'<span style='mso-fareast-language:EN-AU'<a href=" style='font-size:7.5pt;line-height:105%;font-family:"Times New Roman",serif;color:black'> style='font-size:12.0pt;line-height:105%;font-family:"Times New Roman",serif;mso-fareast-language:EN-AU'<o:p</o:p</span</p</td<td width="40%" style='width:40.5%;padding:.75pt .75pt .75pt .75pt;height:9.75pt'<p class=MsoNormal align=right style='text-align:right;line-height:105%'<b<span style='font-size:10.0pt;line-height:105%;font-family:"Times New Roman",serif;color:#882124;mso-fareast-language:EN-AU'>ACN 060 885 387</span</b<span style='font-size:12.0pt;line-height:105%;font-family:"Times New Roman",serif;mso-fareast-language:EN-AU'<o:p</o:p</span</p</td</tr<tr<td style='padding:.75pt .75pt .75pt .75pt'<p class=MsoNormal style='line-height:105%'<a href=" style='font-size:7.5pt;line-height:105%;font-family:"Times New Roman",serif;color:black;mso-fareast-language:EN-AU;text-decoration:none'<img border=0 width=79 height=15 id="Picture_x0020_3" src="cid:92EDE0"</span</a<span style='font-size:12.0pt;line-height:105%;font-family:"Times New Roman",serif;mso-fareast-language:EN-AU'<o:p</o:p</span</p</td<td colspan=4 style='padding:.75pt .75pt .75pt .75pt'</td</trtr<td colspan=5 style='padding:.75pt .75pt .75pt .75pt'<p class=MsoNormal align=center style='text-align:center;line-height:105%'<b<span style='color:maroon'>Usual environmental request and legal notices apply.</span</b<o:p</o:p</p</td</tr</table<p class=MsoNormal align=center style='text-align:center'<b<span style='mso-fareast-language:EN-AU'<o:p </o:p</span</b</p<p class=MsoNormalo:pnbsp;</o:p</p</div</body</html>
End of 12 January
11 January2017
The following subroutine works in ABPControl.xlsm, but does not work in Public LaunchEmail.xlsm
Sub testdim()
Dim LEPath$
Dim LEMailAsOutlook.MailItem
MsgBox "This works"
End Sub
Both applications have the same tools reference (see below)
The difference is the autofill situations
When, in ABPControl.xlsm, I type “DIM LEMail as O” the autofill presented the following
In PublicLaunchEmail.xlsm it differs as outlook is not available. What I see is
w
Tools reference comparison
ABPcontrol.xlsm
Public LaunchEmail.xlsm
Sub testLaunchEmail()
' Material supplied by Richard at Just Answer
'What you need to do is add it as an attachment then reference it to show it in the email
'
'this is the specific code you use
'
'.Attachments.Add "Path to image eg c:\image.jpg", olByValue, 0
'
'Then you use
'
'LEMail.HTMLBody = .HTMLBody & "<br<B>Embedded Image:</B<br>" _ & "<imgsrc='cid:image.jpg'" & "width='500' height='200'<br>" _ & "<br>Best Regards, <brSumit</font</span>" .Display
'
'Just be sure to keep the HTML Body imgsrc the same as the name of the attachment.
' Purpose is to test LaunchEmail subroutine See subroutine for description
Dim TLEAddressee$
Dim TLESubject$
Dim TLEBody$
Dim TLEPath$
Dim TLETop! ' Position in centimetres
Dim TLELeft! ' Position in centimetres
Dim TLEHeight! ' Dimension in centimetres
Dim TLEWidth! ' Dimension in centimetres
' Purpose is to test LaunchEmail subroutine See subroutine for description"
TLEAddressee = ""
TLESubject = " Test of launch email with embedded file"
' TLEPath = "C:\Users\dbarton\Pictures\LOGOUBANK.JPG" This is for Barton Consultancy JustAnswer can change this the idea is to be able to insert a Jpg and htm file
TLEPath = "C:\Users\dbarton\Pictures\LOGOUBANK.JPG"
TLETop = 6
TLELeft = 3
TLEWidth = 4
TLEHeight = 5
TLEAddressee = InputBox("Addressee", , TLEAddressee)
TLEPath = InputBox("File to be inserted", , TLEPath)
TLETop = InputBox("Top position centimetres ", , TLETop)
TLELeft = InputBox("Left position centimetres ", , TLELeft)
TLEHeight = InputBox("Height centimetres ", , TLEHeight)
TLEWidth = InputBox("Width centimetres ", , TLEWidth)
TLEBody = "This is a test of LaunchEmail putting the image" & TLEPath" at position top, left and dimensions width , height " & TLETop & " " & TLELeft & " " & TLEWidth & " " & TLEHeight & " cms "
Call LaunchEmail(TLEAddressee, "", "", TLESubject, TLEBody, TLEPath, "", TLETop, TLELeft, TLEWidth, TLEHeight, True)
End Sub
' !!!!!!!!!!!!!!!!!!!!!! LAUNCH EMAIL !!!!!!!!!!!!!!!!!!!!!!!
'Subroutine to launch an email
' Source
' This requires the reference Microsoft Outlook Object library to be invoked in Tools References
Sub LaunchEmail(LETo$, LECC$, LEBCC$, LESubj$, LEBody$, LEEmbed$, LEAttach$, LETop!, LELeft!, LEWidth!, LEHeight!, LEDisp As Boolean)
' parameters are To, CC,BCC, Subject, Body,File to be embedded in email body _
LEAttach is "" if no file is to be added "1" if the active workbook is to be saved then attached and _
"2" if the active workbook is to be attached without saving if there is no file to be attached, _
LEAttach is "" in the context of VBA for access but can be used in excel _
LEtop, left height and widtth relate to embedded file _
LEDisp =True if message is to display before sending _
Dim LEPath$
Dim LEMailAsOutlook.MailItem
ConstletWIPS = 457 ' 457 twips per centimetre
Dim LEPosn% ' Position of end of HTML body stored in LETextWorks
Dim LETextWork$ ' Text working area
Dim LETextInsert$ ' Text to be inserted into HTML Body
Dim LENs AsOutlook.Namespace
Set LEApp = New Outlook.Application
Set LENs = LEApp.GetNamespace("MAPI")
LENs.Logon
Set LEMail = LEApp.CreateItem(olMailItem)
If LETo > "" Then LEMail.to = LETo
If LECC > "" Then LEMail.CC = LECC
If LEBCC > "" Then LEMail.BCC = LEBCC
If LESubj > "" Then LEMail.Subject = LESubj
If LEBody > "" Then LEMail.Body = LEBody
Debug.PrintLEMail.Body
Debug.PrintLEMail.HTMLBody
' Subroutine works to here
If LEEmbed = "" Then GoToLEEmbedDone
.Attachments.AddLEEmbed
'Then you use
'
LEMail.HTMLBody = .HTMLBody & "<br<B>Embedded Image:</B<br>" & "<imgsrc='" & LEEmbed & "'" & "width='500' height='200'<br>" & "<br>Best Regards, <brSumit</font</span>"
' This is DB's previous attempt
'LETextWork = LEMail.HTMLBody
' Set up the HTML text to insert the embedded file THIS IS WHERE I NEED JUSTANSWER HELP
'LETextInsert = "<imgsrc='" & LEEmbed & "' height=" & LEHeight * letWIPS & " width=" & LEWidth * letWIPS & " Top=" & LETop * letWIPS & " Left=" & LELeft * letWIPS & ">" & Chr(10)
'LEPosn = InStr(1, LETextWork, "</BODY>") ' Find position of coculsion of body text HTML instruction
'LETextWork = Left(LETextWork, LEPosn - 1) & LETextInsert & Right(LETextWork, Len(LETextWork) - LEPosn + 1)
'Debug.PrintLETextWork
' LEMail.HTMLBody = LETextWork
Debug.PrintLEMail.HTMLBody
LEEmbedDone:
'Subroutine works from here
If LEAttach = "" Then GoToLEAttachDone
LEPath = ActiveWorkbook.Path & "\" & ActiveWorkbook.Name
If LEAttach = "1" Then
' MsgBox" Seeking to save and attach active work book"
ActiveWorkbook.Save
LEAttach = LEPath
End If
If LEAttach = "2" Then LEAttach = LEPath
LEMail.Attachments.AddLEAttach
LEAttachDone:
If LEDisp = True Then LEMail.display Else LEMail.Send
End Sub
References screen shot
End Sub