+ Reply to Thread
Results 1 to 2 of 2

Macro that sends emails with embedded images, but images not displaying on all mail apps

  1. #1
    Registered User
    Join Date
    01-27-2015
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1

    Macro that sends emails with embedded images, but images not displaying on all mail apps

    Guys,

    This is my first post here, but i have been using your forums for quite some time. Even though my skills have developed, i have run into some trouble now with a macro that sends an excel range as an image in an outlook email. I am using 2010 Excel and Outlook.

    The problem that i have is as follows, I am able to send the images and attachments as i need and want to, however the images are only displayed in the body of the email when the email is opened in outloook. When i open it in another mail program the only thing that appears is a box the size of the image with the image source name in the upper left hand. The code i am using is below, it is by no means perfect, if you have feedback suggestions i am definitely open to it. The main issue i am trying to solve is the display of images in other mail apps. Here is the code:

    Sub Macro1()
    '
    ' Macro1 Macro
    '
    Dim pvt As PivotTable
    Dim ws As Worksheet
    Dim wb As Workbook

    For Each ws In ActiveWorkbook.Worksheets
    For Each pvt In ws.PivotTables
    With pvt
    .HasAutoFormat = False
    .SaveData = False
    End With
    Next pvt
    Next ws
    End Sub


    Sub sendMail()
    Application.Calculation = xlManual
    ActiveWorkbook.RefreshAll
    With Application
    .ScreenUpdating = False
    .EnableEvents = False
    End With

    Dim TempFilePath As String

    Sheets("Output").Select

    Dim IsCreated As Boolean
    Dim i As Long
    Dim PdfFile As String
    Dim dt As String
    'Dim colAttach As Outlook.Attachments
    'Dim oAttach As Outlook.Attachment


    ' Define PDF filename
    dt = Format(CStr(Date - 1), "mm.dd.yy")
    PdfFile = ActiveWorkbook.FullName
    i = InStrRev(PdfFile, ".")
    If i > 1 Then PdfFile = Left(PdfFile, i - 1)
    PdfFile = PdfFile & "_" & dt & ".pdf"

    ' Export activesheet as PDF
    With ActiveSheet
    .ExportAsFixedFormat Type:=xlTypePDF, Filename:=PdfFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
    End With

    ' Delete PDF file
    'Kill PdfFile


    'Create a new Microsoft Outlook session
    Set appOutlook = CreateObject("outlook.application")
    'create a new message
    Set Message = appOutlook.CreateItem(olMailItem)
    ' Set colAttach = oEmail.Attachments
    ' Set oAttach = colAttach.Add("C:\temp\logo.jpg")
    ' Set olkPA = oAttach.PropertyAccessor

    With Message
    .Subject = "CONFIDENTIAL: Daily Financial Flash as of " & (Date - 1)


    .HTMLBody = "<span LANG=EN>" _
    & "<p class=style2><span LANG=EN><font FACE=Calibri SIZE=3>" _
    & "Team,<br ><br >Daily Metrics Below: " _
    & "<br ><br > " _
    & "<br>For questions contact me.<BR>"

    'first JPG file
    Call createJpg("Output", "A32:L60", "RevenueGrowth")
    'we attached an invisible the embedded image
    TempFilePath = Environ$("temp") & "\"
    .Attachments.Add TempFilePath & "RevenueGrowth.jpg", olByValue


    'second JPG file currently comented out
    Call createJpg("Output", "A63:L90", "DailyRevenue")
    'we attached an invisible the embedded image
    TempFilePath = Environ$("temp") & "\"
    .Attachments.Add TempFilePath & "DailyRevenue.jpg", olByValue
    'Then we add an html <img src=''> link to this image
    'Note than you can customize width and height - not mandatory
    '& "<img src='cid:DashboardFile2.jpg'"this goes below after the <BR> stuff

    .HTMLBody = .HTMLBody & "<br><B>Daily Metrics:</B><br>" _
    & "<br><B>Revenue Growth</B><br>" _
    & "<img src=""cid:RevenueGrowth.jpg""" _
    & "<br ><br >" _
    & "<br><B>Daily Revenue</B><br>" _
    & "<img src=""cid:DailyRevenue.jpg""" _
    & "<br>Cheers,<br ><br >SRA</font></span>"

    .To = "[email protected]"
    .CC = ""
    .Attachments.Add PdfFile
    .Display
    '.Send
    End With

    With Application
    .ScreenUpdating = True
    .EnableEvents = True
    End With
    Application.Calculation = xlCalculationAutomatic
    End Sub

    Sub createJpg(Namesheet As String, nameRange As String, nameFile As String)
    ThisWorkbook.Activate
    Worksheets(Namesheet).Activate
    Set Plage = ThisWorkbook.Worksheets(Namesheet).Range(nameRange)
    Plage.CopyPicture
    With ThisWorkbook.Worksheets(Namesheet).ChartObjects.Add(Plage.Left, Plage.Top, Plage.Width, Plage.Height)
    .Activate
    .Chart.Paste
    .Chart.Export Environ$("temp") & "\" & nameFile & ".jpg", "JPG"
    End With
    Worksheets(Namesheet).ChartObjects(Worksheets(Namesheet).ChartObjects.Count).Delete
    Set Plage = Nothing
    End Sub


    Let me know if you need more info, or if i should post this differently. Thanks for all your help so far...this is an awesome forum.

  2. #2
    Registered User
    Join Date
    04-13-2016
    Location
    Brazil
    MS-Off Ver
    2013
    Posts
    1

    Re: Macro that sends emails with embedded images, but images not displaying on all mail ap

    Hey
    I have a doubt on this code ...

    Please Login or Register  to view this content.

    How can i change the name of the sheet (ex:"Output") for an active sheet. Because when i copy a sheet the code don't work anymore because the reference name.
    Please, help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. referencing embedded images/files
    By jamesDecker in forum Excel General
    Replies: 1
    Last Post: 06-13-2013, 09:18 AM
  2. How to save Linked images on excel as embedded images.
    By jonelamora in forum Excel General
    Replies: 0
    Last Post: 04-18-2013, 10:29 PM
  3. referring to cells with embedded images
    By teewye in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-06-2012, 03:39 PM
  4. Embedded images not displaying in Excel
    By tjahelka in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-31-2009, 02:40 PM
  5. Changing Linked Images into Embedded Images
    By ericjover in forum Excel General
    Replies: 0
    Last Post: 01-05-2009, 02:23 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1