Email active sheet or embedded objects not as an attachment

Tbone

New Member
Joined
Jun 4, 2002
Messages
20
I have a worksheet that contains embedded objects. Users are making selections with dropdowns and check boxes. How do I copy this worksheet, actually just the embedded objects, into the body of the email. The embedded object is grouped. I can send it as an attachment, but I rather have the results pasted into the body of the email. I can do this physical, but of course I need help doing this through VBA. I'm using Excel 2000 & Outlook 2000.

Thanks

Tbone
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
NOT an easy task to do.....but try this;

Assumes you have a grouped object;

<pre><FONT COLOR="#00007F">Option</FONT> <FONT COLOR="#00007F">Explicit</FONT>


<FONT COLOR="#007F00">'To create an HTML message that included an embedded image -- that, instead,</FONT>
<FONT COLOR="#007F00">'all "" <img> "" tags had to use full URLs to public web addresses.</FONT>
<FONT COLOR="#007F00">'The impossible has become possible, though, through the efforts of Outlook MVP Neo,</FONT>
<FONT COLOR="#007F00">'who devised a method that uses undocumented MAPI properties and CDO.</FONT>

<FONT COLOR="#007F00">'CDO = Microsoft® Collaboration Data Objects</FONT>
<FONT COLOR="#007F00">'CDO does not represent a new messaging model, but rather an additional scripting interface</FONT>
<FONT COLOR="#007F00">'to the Messaging Application Programming Interface (MAPI) model.</FONT>

<FONT COLOR="#007F00">'for more info see;</FONT>
<FONT COLOR="#007F00">'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdo/html/_olemsg_overview_of_cdo.asp</FONT>

<FONT COLOR="#007F00">'For versions see;</FONT>
<FONT COLOR="#007F00">'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncdsys/html/cdo_roadmap.asp</FONT>

<FONT COLOR="#007F00">'In VBA or Visual Basic you will need to add a reference to the CDO 1.21 library to use this procedure.</FONT>
<FONT COLOR="#007F00">'For client applications, you should install Outlook in order to install CDO.</FONT>
<FONT COLOR="#007F00">'In Outlook 2000 and Outlook 2002, CDO is included, but you must explicitly select</FONT>
<FONT COLOR="#007F00">'it during setup.</FONT>

<FONT COLOR="#007F00">'Microsoft CDO 1.21 Library</FONT>
<FONT COLOR="#007F00">'MAPI</FONT>
<FONT COLOR="#007F00">'GUID = {3FA7DEA7-6438-101B-ACC1-00AA00423326}</FONT>
<FONT COLOR="#007F00">'Path C:\PROGRA~1\COMMON~1\System\Mapi\1033\NT\CDO.DLL</FONT>
<FONT COLOR="#007F00">'GUID Ref .AddFromGuid "{3FA7DEA7-6438-101B-ACC1-00AA00423326}",1,21</FONT>
<FONT COLOR="#007F00">'.Item("MAPI")</FONT>


<FONT COLOR="#00007F">Sub</FONT> InsertObjectInEmail_V1()
<FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00">'//</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT> Ivan F Moala 17th March 2003</FONT>
<FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00">'//</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT> Amendment</FONT>
<FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00">'//</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT> Ivan F Moala 30th June 2003</FONT>
<FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00">'//</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT> Ivan F Moala 17th Sept 2003:- <FONT COLOR="#00007F">Set</FONT> as Grouped <FONT COLOR="#00007F">Object</FONT></FONT>
<FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00">'//</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT> Thanks to Outlook MVP Neo</FONT>
<FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00">'//</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT> Original used "<img src=" image full address</FONT>
<FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00">'//</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT> So the image had to have a url web address to</FONT>
<FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00">'//</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT> be viewed properly</FONT>
<FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00">'//</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT> Testing under Xl2000 / WinXP</FONT>

<FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00">'//</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT> Dimension variables, lets use Latebinding</FONT>
<FONT COLOR="#00007F">Dim</FONT> oOutlookApp <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Object</FONT>
<FONT COLOR="#00007F">Dim</FONT> oOutlookMessage <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Object</FONT>
<FONT COLOR="#00007F">Dim</FONT> oFSObj <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Object</FONT>
<FONT COLOR="#00007F">Dim</FONT> strHTMLBody <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">String</FONT>
<FONT COLOR="#00007F">Dim</FONT> strTempFilePath <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">String</FONT>
<FONT COLOR="#00007F">Dim</FONT> oOutlookAppAttach <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Object</FONT>
<FONT COLOR="#00007F">Dim</FONT> oOutlook_Att <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Object</FONT>
<FONT COLOR="#00007F">Dim</FONT> strEntryID <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">String</FONT>
<FONT COLOR="#00007F">Dim</FONT> oSession <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Object</FONT>

<FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00">'//</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT> Use Early binding = Reference CDO</FONT>
<FONT COLOR="#00007F">Dim</FONT> oMsg <FONT COLOR="#00007F">As</FONT> MAPI.Message
<FONT COLOR="#00007F">Dim</FONT> oAttachs <FONT COLOR="#00007F">As</FONT> MAPI.Attachments
<FONT COLOR="#00007F">Dim</FONT> oAttach <FONT COLOR="#00007F">As</FONT> MAPI.Attachment
<FONT COLOR="#00007F">Dim</FONT> colFields <FONT COLOR="#00007F">As</FONT> MAPI.Fields
<FONT COLOR="#00007F">Dim</FONT> oField <FONT COLOR="#00007F">As</FONT> MAPI.Field
<FONT COLOR="#00007F">Dim</FONT> ID <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Object</FONT>
<FONT COLOR="#00007F">Dim</FONT> objPict <FONT COLOR="#00007F">As</FONT> Shape
<FONT COLOR="#00007F">Dim</FONT> MyChart <FONT COLOR="#00007F">As</FONT> Chart
<FONT COLOR="#00007F">Dim</FONT> GrpCtrl <FONT COLOR="#00007F">As</FONT> Shape
<FONT COLOR="#00007F">Dim</FONT> blnPict <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Boolean</FONT>


<FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00">'//</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT> You need to run this in the Sheet that has the Image!</FONT>
<FONT COLOR="#00007F">For</FONT> Each GrpCtrl In ActiveSheet.Shapes
<FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00">'//</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT>6 = grouped controls</FONT>
<FONT COLOR="#00007F">If</FONT> GrpCtrl.Type = 6 <FONT COLOR="#00007F">Then</FONT>
<FONT COLOR="#00007F">If</FONT> MsgBox("Email this Grouped control:= " & GrpCtrl.Name & vbCr & _
"Use this ? ", vbYesNo) = vbYes <FONT COLOR="#00007F">Then</FONT>
<FONT COLOR="#00007F">Set</FONT> objPict = ActiveSheet.Shapes(GrpCtrl.Name)
blnPict = <FONT COLOR="#00007F">True</FONT>
<FONT COLOR="#00007F">Exit</FONT> <FONT COLOR="#00007F">For</FONT>
<FONT COLOR="#00007F">End</FONT> <FONT COLOR="#00007F">If</FONT>
<FONT COLOR="#00007F">End</FONT> <FONT COLOR="#00007F">If</FONT>
<FONT COLOR="#00007F">Next</FONT>

<FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00">'//</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT> Make sure that an Image is set</FONT></FONT></FONT></FONT></FONT>
<FONT COLOR="#00007F">If</FONT> Not blnPict <FONT COLOR="#00007F">Then</FONT> MsgBox "No Picture selected!": <FONT COLOR="#00007F">Exit</FONT> <FONT COLOR="#00007F">Sub</FONT>

<FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00">'//</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT>
<FONT COLOR="#007F00">'Get the temp folder path</FONT>
<FONT COLOR="#00007F">Set</FONT> oFSObj = CreateObject("Scripting.FilesystemObject")

strTempFilePath = oFSObj.GetSpecialFolder(2)
strTempFilePath = strTempFilePath & "\MyImg.gif"

<FONT COLOR="#00007F">With</FONT> objPict
.CopyPicture 1, 2
<FONT COLOR="#00007F">Set</FONT> MyChart = ActiveSheet.ChartObjects.Add(1, 1, .Width + 8, .Height + 8).Chart
<FONT COLOR="#00007F">End</FONT> <FONT COLOR="#00007F">With</FONT>

<FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00">'//</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT> Export the chart. We'll use it later</FONT>
<FONT COLOR="#00007F">With</FONT> MyChart
.Paste
.Export strTempFilePath
.Parent.Delete
<FONT COLOR="#00007F">End</FONT> <FONT COLOR="#00007F">With</FONT>

<FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00">'//</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT>
<FONT COLOR="#007F00">'Create an instance of Outlook (or use existing instance if it already exists</FONT>
<FONT COLOR="#00007F">Set</FONT> oOutlookApp = CreateObject("Outlook.Application")

<FONT COLOR="#007F00">'Create a mail item</FONT>
<FONT COLOR="#00007F">Set</FONT> oOutlookMessage = oOutlookApp.CreateItem(0)
<FONT COLOR="#00007F">Set</FONT> oOutlookAppAttach = oOutlookMessage.Attachments
<FONT COLOR="#007F00">' add graphic as attachment to Outlook message</FONT>
<FONT COLOR="#007F00">' change path to graphic as needed</FONT>
<FONT COLOR="#00007F">Set</FONT> oOutlook_Att = oOutlookAppAttach.Add(strTempFilePath)

<FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00">'//</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT> Lets save the msg, this is so that the EntryID property</FONT>
<FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00">'//</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT> is set.</FONT>
oOutlookMessage.Close olSave

<FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00">'//</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT> Lets get the unique entry ID of the object.</FONT>
<FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00">'//</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT> EntryID property corresponds to the MAPI property PR_ENTRYID.</FONT>
<FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00">'//</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT> MAPI systems assign a permanent, unique ID string when an object</FONT>
<FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00">'//</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT> is created that does not change from one MAPI session to another.</FONT>
<FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00">'//</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT> Also, the EntryID changes when an item is moved into another folder.</FONT>
strEntryID = oOutlookMessage.EntryID

<FONT COLOR="#00007F">Set</FONT> oOutlookMessage = <FONT COLOR="#00007F">Nothing</FONT>
<FONT COLOR="#007F00">' *** POSITION CRITICAL *** you must dereference the</FONT>
<FONT COLOR="#007F00">' attachment objects before changing their properties</FONT>
<FONT COLOR="#007F00">' via CDO</FONT>
<FONT COLOR="#00007F">Set</FONT> oOutlookAppAttach = <FONT COLOR="#00007F">Nothing</FONT>

<FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00">'//</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT> initialize CDO session</FONT>
<FONT COLOR="#00007F">On</FONT> <FONT COLOR="#00007F">Error</FONT> <FONT COLOR="#00007F">Resume</FONT> <FONT COLOR="#00007F">Next</FONT>
<FONT COLOR="#00007F">Set</FONT> oSession = CreateObject("MAPI.Session")
oSession.Logon "", "", <FONT COLOR="#00007F">False</FONT>, <FONT COLOR="#00007F">False</FONT>

<FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00">'//</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT> get the message created earlier</FONT>
<FONT COLOR="#00007F">Set</FONT> oMsg = oSession.GetMessage(strEntryID)

<FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00">'//</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT> set properties of the attached graphic that make</FONT>
<FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00">'//</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT> it embedded and give it an ID for use in an <IMG> tag</FONT>
<FONT COLOR="#00007F">Set</FONT> oAttachs = oMsg.Attachments
<FONT COLOR="#00007F">Set</FONT> oAttach = oAttachs.Item(1)
<FONT COLOR="#00007F">Set</FONT> colFields = oAttach.Fields

<FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00">'//</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT> <FONT COLOR="#00007F">Set</FONT> oField = oFieldsColl.Add (name, Class [, value] [, PropsetID] )</FONT>
<FONT COLOR="#00007F">Set</FONT> oField = colFields.Add(CdoPR_ATTACH_MIME_TAG, "image/gif")
<FONT COLOR="#00007F">Set</FONT> oField = colFields.Add(&H3712001E, "MyIdent")

oMsg.Fields.Add "{0820060000000000C000000000000046}0x8514", 11, <FONT COLOR="#00007F">True</FONT>
oMsg.Update

<FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00">'//</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT> Here put any HTML you want - this is just an example</FONT>
strHTMLBody = "This is the Image you were looking for.
"
strHTMLBody = strHTMLBody & "<FONT COLOR="#00007F">Get</FONT> back to me ASAP
"
strHTMLBody = strHTMLBody & "Looking forward to your reply.


"
strHTMLBody = strHTMLBody & "Ivan F Moala

<hr>"

<FONT COLOR="#007F00">' get the Outlook MailItem again</FONT>
<FONT COLOR="#00007F">Set</FONT> oOutlookMessage = oOutlookApp.GetNamespace("MAPI").GetItemFromID(strEntryID)

<FONT COLOR="#007F00">' add HTML content -- the <IMG> tag</FONT>
<FONT COLOR="#00007F">With</FONT> oOutlookMessage
.HTMLBody = strHTMLBody & "<IMG align=baseline border=0 hspace=0 SRC=cid:MyIdent>"
.Close (olSave)
.Display
<FONT COLOR="#00007F">End</FONT> <FONT COLOR="#00007F">With</FONT>

<FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00"><FONT COLOR="#007F00">'//</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT> cleanup</FONT>
<FONT COLOR="#00007F">Set</FONT> oFSObj = <FONT COLOR="#00007F">Nothing</FONT>
<FONT COLOR="#00007F">Set</FONT> oField = <FONT COLOR="#00007F">Nothing</FONT>
<FONT COLOR="#00007F">Set</FONT> colFields = <FONT COLOR="#00007F">Nothing</FONT>
<FONT COLOR="#00007F">Set</FONT> oMsg = <FONT COLOR="#00007F">Nothing</FONT>
<FONT COLOR="#00007F">Set</FONT> oAttachs = <FONT COLOR="#00007F">Nothing</FONT>
<FONT COLOR="#00007F">Set</FONT> oAttach = <FONT COLOR="#00007F">Nothing</FONT>
<FONT COLOR="#00007F">Set</FONT> colFields = <FONT COLOR="#00007F">Nothing</FONT>

oSession.Logoff

<FONT COLOR="#00007F">Set</FONT> oSession = <FONT COLOR="#00007F">Nothing</FONT>
<FONT COLOR="#00007F">Set</FONT> oOutlookApp = <FONT COLOR="#00007F">Nothing</FONT>
<FONT COLOR="#00007F">Set</FONT> oOutlookMessage = <FONT COLOR="#00007F">Nothing</FONT>

Kill strTempFilePath

<FONT COLOR="#00007F">End</FONT> <FONT COLOR="#00007F">Sub</FONT>


</pre>
 
Upvote 0
Re: Email active sheet or embedded objects not as an attachm

WOW! I didn't think it would take all that. Just an attachment is easy, but this is a challenge. Thanks for the code Ivan, I will try this out, and post another message to let you and everyone else know if it worked out for me.
 
Upvote 0
Re: Email active sheet or embedded objects not as an attachm

I have copied the code and with no modification so far, I am unable to compile. error occurs at olSave....any idea why this happens. I have added the reference CDO 1.21

TBone
 
Upvote 0
Re: Email active sheet or embedded objects not as an attachm

Let's see if this works. Very cool code Ivan !

<font face=Courier New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN>

<SPAN style="color:#007F00">'To create an HTML message that included an embedded image -- that, instead,</SPAN>
<SPAN style="color:#007F00">'all "<IMG>" tags had to use full URLs to public web addresses.</SPAN>
<SPAN style="color:#007F00">'The impossible has become possible, though, through the efforts of Outlook MVP Neo,</SPAN>
<SPAN style="color:#007F00">'who devised a method that uses undocumented MAPI properties and CDO.</SPAN>

<SPAN style="color:#007F00">'CDO = Microsoft® Collaboration Data Objects</SPAN>
<SPAN style="color:#007F00">'CDO does not represent a new messaging model, but rather an additional scripting interface</SPAN>
<SPAN style="color:#007F00">'to the Messaging Application Programming Interface (MAPI) model.</SPAN>

<SPAN style="color:#007F00">'for more info see;</SPAN>
<SPAN style="color:#007F00">'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdo/html/_olemsg_overview_of_cdo.asp</SPAN>

<SPAN style="color:#007F00">'For versions see;</SPAN>
<SPAN style="color:#007F00">'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncdsys/html/cdo_roadmap.asp</SPAN>

<SPAN style="color:#007F00">'In VBA or Visual Basic you will need to add a reference to the CDO 1.21 library to use this procedure.</SPAN>
<SPAN style="color:#007F00">'For client applications, you should install Outlook in order to install CDO.</SPAN>
<SPAN style="color:#007F00">'In Outlook 2000 and Outlook 2002, CDO is included, but you must explicitly select</SPAN>
<SPAN style="color:#007F00">'it during setup.</SPAN>

<SPAN style="color:#007F00">'Microsoft CDO 1.21 Library</SPAN>
<SPAN style="color:#007F00">'MAPI</SPAN>
<SPAN style="color:#007F00">'GUID = {3FA7DEA7-6438-101B-ACC1-00AA00423326}</SPAN>
<SPAN style="color:#007F00">'Path C:\PROGRA~1\COMMON~1\System\Mapi\1033\NT\CDO.DLL</SPAN>
<SPAN style="color:#007F00">'GUID Ref .AddFromGuid "{3FA7DEA7-6438-101B-ACC1-00AA00423326}",1,21</SPAN>
<SPAN style="color:#007F00">'.Item("MAPI")</SPAN>


<SPAN style="color:#00007F">Sub</SPAN> InsertObject<SPAN style="color:#00007F">In</SPAN>Email_V1()
    <SPAN style="color:#007F00">'// Ivan F Moala 17th March 2003</SPAN>
    <SPAN style="color:#007F00">'// Amendment</SPAN>
    <SPAN style="color:#007F00">'// Ivan F Moala 30th June 2003</SPAN>
    <SPAN style="color:#007F00">'// Ivan F Moala 17th Sept 2003:- Set as Grouped Object</SPAN>
    <SPAN style="color:#007F00">'// Thanks to Outlook MVP Neo</SPAN>
    <SPAN style="color:#007F00">'//     Original used  "<IMG>"</SPAN>
    <SPAN style="color:#007F00">'//     So the image had to have a url web address to</SPAN>
    <SPAN style="color:#007F00">'//     be viewed properly</SPAN>
    <SPAN style="color:#007F00">'//     Testing under Xl2000 / WinXP</SPAN>

    <SPAN style="color:#007F00">'// Dimension variables, lets use Latebinding</SPAN>
    <SPAN style="color:#00007F">Dim</SPAN> oOutlookApp <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Object</SPAN>
    <SPAN style="color:#00007F">Dim</SPAN> oOutlookMessage <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Object</SPAN>
    <SPAN style="color:#00007F">Dim</SPAN> oFSObj <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Object</SPAN>
    <SPAN style="color:#00007F">Dim</SPAN> strHTMLBody <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
    <SPAN style="color:#00007F">Dim</SPAN> strTempFilePath <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
    <SPAN style="color:#00007F">Dim</SPAN> oOutlookAppAttach <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Object</SPAN>
    <SPAN style="color:#00007F">Dim</SPAN> oOutlook_Att <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Object</SPAN>
    <SPAN style="color:#00007F">Dim</SPAN> strEntryID <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
    <SPAN style="color:#00007F">Dim</SPAN> oSession <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Object</SPAN>

    <SPAN style="color:#007F00">'// Use Early binding = Reference CDO</SPAN>
    <SPAN style="color:#00007F">Dim</SPAN> oMsg <SPAN style="color:#00007F">As</SPAN> MAPI.Message
    <SPAN style="color:#00007F">Dim</SPAN> oAttachs <SPAN style="color:#00007F">As</SPAN> MAPI.Attachments
    <SPAN style="color:#00007F">Dim</SPAN> oAttach <SPAN style="color:#00007F">As</SPAN> MAPI.Attachment
    <SPAN style="color:#00007F">Dim</SPAN> colFields <SPAN style="color:#00007F">As</SPAN> MAPI.Fields
    <SPAN style="color:#00007F">Dim</SPAN> oField <SPAN style="color:#00007F">As</SPAN> MAPI.Field
    <SPAN style="color:#00007F">Dim</SPAN> ID <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Object</SPAN>
    <SPAN style="color:#00007F">Dim</SPAN> objPict <SPAN style="color:#00007F">As</SPAN> Shape
    <SPAN style="color:#00007F">Dim</SPAN> MyChart <SPAN style="color:#00007F">As</SPAN> Chart
    <SPAN style="color:#00007F">Dim</SPAN> GrpCtrl <SPAN style="color:#00007F">As</SPAN> Shape
    <SPAN style="color:#00007F">Dim</SPAN> blnPict <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Boolean</SPAN>


    <SPAN style="color:#007F00">'// You need to run this in the Sheet that has the Image!</SPAN>
    <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> GrpCtrl In ActiveSheet.Shapes
        <SPAN style="color:#007F00">'//6 = grouped controls</SPAN>
        <SPAN style="color:#00007F">If</SPAN> GrpCtrl.Type = 6 <SPAN style="color:#00007F">Then</SPAN>
            <SPAN style="color:#00007F">If</SPAN> MsgBox("Email this Grouped control:= " & GrpCtrl.Name & vbCr & _
                      "Use this ? ", vbYesNo) = vbYes <SPAN style="color:#00007F">Then</SPAN>
                <SPAN style="color:#00007F">Set</SPAN> objPict = ActiveSheet.Shapes(GrpCtrl.Name)
                blnPict = <SPAN style="color:#00007F">True</SPAN>
                <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">For</SPAN>
            <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
    <SPAN style="color:#00007F">Next</SPAN>

    <SPAN style="color:#007F00">'// Make sure that an Image is set</SPAN>
    <SPAN style="color:#00007F">If</SPAN> <SPAN style="color:#00007F">Not</SPAN> blnPict <SPAN style="color:#00007F">Then</SPAN> MsgBox "No Picture selected!": <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN>

    <SPAN style="color:#007F00">'//</SPAN>
    <SPAN style="color:#007F00">'Get the temp folder path</SPAN>
    <SPAN style="color:#00007F">Set</SPAN> oFSObj = CreateObject("Scripting.FilesystemObject")

    strTempFilePath = oFSObj.GetSpecialFolder(2)
    strTempFilePath = strTempFilePath & "\MyImg.gif"

    <SPAN style="color:#00007F">With</SPAN> objPict
        .CopyPicture 1, 2
        <SPAN style="color:#00007F">Set</SPAN> MyChart = ActiveSheet.ChartObjects.Add(1, 1, .Width + 8, .Height + 8).Chart
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>

    <SPAN style="color:#007F00">'// Export the chart. We'll use it later</SPAN>
    <SPAN style="color:#00007F">With</SPAN> MyChart
        .Paste
        .Export strTempFilePath
        .Parent.Delete
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>

    <SPAN style="color:#007F00">'//</SPAN>
    <SPAN style="color:#007F00">'Create an instance of Outlook (or use existing instance if it already exists</SPAN>
    <SPAN style="color:#00007F">Set</SPAN> oOutlookApp = CreateObject("Outlook.Application")

    <SPAN style="color:#007F00">'Create a mail item</SPAN>
    <SPAN style="color:#00007F">Set</SPAN> oOutlookMessage = oOutlookApp.CreateItem(0)
    <SPAN style="color:#00007F">Set</SPAN> oOutlookAppAttach = oOutlookMessage.Attachments
    <SPAN style="color:#007F00">' add graphic as attachment to Outlook message</SPAN>
    <SPAN style="color:#007F00">' change path to graphic as needed</SPAN>
    <SPAN style="color:#00007F">Set</SPAN> oOutlook_Att = oOutlookAppAttach.Add(strTempFilePath)

    <SPAN style="color:#007F00">'// Lets save the msg, this is so that the EntryID property</SPAN>
    <SPAN style="color:#007F00">'// is set.</SPAN>
    oOutlookMessage.Close 0

    <SPAN style="color:#007F00">'// Lets get the unique entry ID of the object.</SPAN>
    <SPAN style="color:#007F00">'// EntryID property corresponds to the MAPI property PR_ENTRYID.</SPAN>
    <SPAN style="color:#007F00">'// MAPI systems assign a permanent, unique ID string when an object</SPAN>
    <SPAN style="color:#007F00">'// is created that does not change from one MAPI session to another.</SPAN>
    <SPAN style="color:#007F00">'// Also, the EntryID changes when an item is moved into another folder.</SPAN>
    strEntryID = oOutlookMessage.EntryID

    <SPAN style="color:#00007F">Set</SPAN> oOutlookMessage = <SPAN style="color:#00007F">Nothing</SPAN>
    <SPAN style="color:#007F00">' *** POSITION CRITICAL *** you must dereference the</SPAN>
    <SPAN style="color:#007F00">' attachment objects before changing their properties</SPAN>
    <SPAN style="color:#007F00">' via CDO</SPAN>
    <SPAN style="color:#00007F">Set</SPAN> oOutlookAppAttach = <SPAN style="color:#00007F">Nothing</SPAN>

    <SPAN style="color:#007F00">'// initialize CDO session</SPAN>
    <SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">Resume</SPAN> <SPAN style="color:#00007F">Next</SPAN>
    <SPAN style="color:#00007F">Set</SPAN> oSession = CreateObject("MAPI.Session")
    oSession.Logon "", "", <SPAN style="color:#00007F">False</SPAN>, <SPAN style="color:#00007F">False</SPAN>

    <SPAN style="color:#007F00">'// get the message created earlier</SPAN>
    <SPAN style="color:#00007F">Set</SPAN> oMsg = oSession.GetMessage(strEntryID)

    <SPAN style="color:#007F00">'// set properties of the attached graphic that make</SPAN>
    <SPAN style="color:#007F00">'// it embedded and give it an ID for use in an <IMG> Tag</SPAN>
    <SPAN style="color:#00007F">Set</SPAN> oAttachs = oMsg.Attachments
    <SPAN style="color:#00007F">Set</SPAN> oAttach = oAttachs.Item(1)
    <SPAN style="color:#00007F">Set</SPAN> colFields = oAttach.Fields

    <SPAN style="color:#007F00">'// Set oField = oFieldsColl.Add (name, Class [, value] [, PropsetID] )</SPAN>
    <SPAN style="color:#00007F">Set</SPAN> oField = colFields.Add(CdoPR_ATTACH_MIME_TAG, "image/gif")
    <SPAN style="color:#00007F">Set</SPAN> oField = colFields.Add(&H3712001E, "MyIdent")

    oMsg.Fields.Add "{0820060000000000C000000000000046}0x8514", 11, <SPAN style="color:#00007F">True</SPAN>
    oMsg.Update

    <SPAN style="color:#007F00">'// Here put any HTML you want - this is just an example</SPAN>
    strHTMLBody = "This is the Image you were looking for.
"
    strHTMLBody = strHTMLBody & "Get back to me ASAP
"
    strHTMLBody = strHTMLBody & "Looking forward to your reply.

"
    strHTMLBody = strHTMLBody & "Ivan F Moala"

    <SPAN style="color:#007F00">' get the Outlook MailItem again</SPAN>
    <SPAN style="color:#00007F">Set</SPAN> oOutlookMessage = oOutlookApp.GetNamespace("MAPI").GetItemFromID(strEntryID)

    <SPAN style="color:#007F00">' add HTML content -- the <IMG> Tag</SPAN>
    <SPAN style="color:#00007F">With</SPAN> oOutlookMessage
        .HTMLBody = strHTMLBody & "<IMG align=baseline border=0 hspace=0 SRC=cid:MyIdent>"
        .Close 0
        .Display
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>

    <SPAN style="color:#007F00">'// cleanup</SPAN>
    <SPAN style="color:#00007F">Set</SPAN> oFSObj = <SPAN style="color:#00007F">Nothing</SPAN>
    <SPAN style="color:#00007F">Set</SPAN> oField = <SPAN style="color:#00007F">Nothing</SPAN>
    <SPAN style="color:#00007F">Set</SPAN> colFields = <SPAN style="color:#00007F">Nothing</SPAN>
    <SPAN style="color:#00007F">Set</SPAN> oMsg = <SPAN style="color:#00007F">Nothing</SPAN>
    <SPAN style="color:#00007F">Set</SPAN> oAttachs = <SPAN style="color:#00007F">Nothing</SPAN>
    <SPAN style="color:#00007F">Set</SPAN> oAttach = <SPAN style="color:#00007F">Nothing</SPAN>
    <SPAN style="color:#00007F">Set</SPAN> colFields = <SPAN style="color:#00007F">Nothing</SPAN>

    oSession.Logoff

    <SPAN style="color:#00007F">Set</SPAN> oSession = <SPAN style="color:#00007F">Nothing</SPAN>
    <SPAN style="color:#00007F">Set</SPAN> oOutlookApp = <SPAN style="color:#00007F">Nothing</SPAN>
    <SPAN style="color:#00007F">Set</SPAN> oOutlookMessage = <SPAN style="color:#00007F">Nothing</SPAN>

    Kill strTempFilePath

<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>


</FONT>
 
Upvote 0
Re: Email active sheet or embedded objects not as an attachm

Thanks Juan. It now complies, but the code still doesn't attach the image into the email as an image. It attaches it as an attachment. I don't know where it's going wrong. I tried to debug it, but can't figure out why it's not an image of the group.

Tbone
 
Upvote 0
Re: Email active sheet or embedded objects not as an attachm

Mhm, it worked ok using Outlook 2002. Don't have (Can't have !) Outlook 2000 so, don't know if that may be it...
 
Upvote 0
Re: Email active sheet or embedded objects not as an attachm

Tbone said:
Thanks Juan. It now complies, but the code still doesn't attach the image into the email as an image. It attaches it as an attachment. I don't know where it's going wrong. I tried to debug it, but can't figure out why it's not an image of the group.

Tbone

Try this version

http://www.xcelfiles.com/EmailImg.html
 
Upvote 0

Forum statistics

Threads
1,215,731
Messages
6,126,538
Members
449,316
Latest member
sravya

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top