Embedding Several Images into an Email using VBA from Excel to Outlook and using CID
<p>I'm trying to embed several graphs (as PNGs) from a Excel VBA Macro to Outlook.
The images embed however, it's not all 8 images but the first one repeated 8 times.</p>

<pre><code>Sub Test()
    Dim sheetNumber, size, i As Integer
    Dim chartNames(), FNames() As String
    Dim objChrt As ChartObject
    Dim myChart As Chart


    'Activate Charts Sheet
    Sheets("GRAFICAS").Activate
    'Calculate Number of Charts in Sheet
    chartNumber = ActiveSheet.ChartObjects.Count
    'Redimension Arrays to fit all Chart Export Names
    ReDim chartNames(chartNumber)
    ReDim FNames(chartNumber)
    'Loops through all the charts in the GRAFICAS sheet
    For i = 1 To chartNumber
        'Select chart with index i
        Set objChrt = ActiveSheet.ChartObjects(i)
        Set myChart = objChrt.Chart
        'Generate a name for the chart
        chartNames(i) = "myChart" &amp; i &amp; ".png"

        On Error Resume Next
        Kill ThisWorkbook.Path &amp; "\" &amp; chartNames(i)
        On Error GoTo 0
        'Export Chart
        myChart.Export Filename:=Environ$("TEMP") &amp; "\" &amp; chartNames(i), Filtername:="PNG"
        'Save path to exported chart
        FNames(i) = Environ$("TEMP") &amp; "\" &amp; chartNames(i)
    Next i
   'Declare the Object variables for Outlook.
    Dim objOutlook As Object
    'Verify Outlook is open.
    On Error Resume Next
    Set objOutlook = GetObject(, "Outlook.Application")
    'If Outlook is not open, end the Sub.
    If objOutlook Is Nothing Then
        Err.Clear
         MsgBox _
        "Cannot continue, Outlook is not open.", , _
        "Please open Outlook and try again."
        Exit Sub
    'Outlook is determined to be open, so OK to proceed.
    Else
        'Establish an Object variable for a mailitem.
        Dim objMailItem As Object
        Set objMailItem = objOutlook.CreateItem(0)
        'Build the mailitem.
        Dim NewBody As String
            On Error Resume Next
            With objMailItem
                .To = "dummy@test.com"
                .Subject = "Testing Lesson 31 email code"
                .Importance = 1 'Sets it as Normal importance (Low = 0 and High = 2)
                'Change the Display command to Send without reviewing the email.
               ' .Display
            End With
           For i = 1 To chartNumber
               objMailItem.Attachments.Add FNames(i)
               'Put together the HTML to embed
                NewBody = NewBody + HTMLcode &amp; "&lt;div align=center&gt;" &amp; "&lt;IMG src=cid: myChart" &amp; i &amp; ".png&gt;&lt;/img&gt;" &amp; "&lt;/div&gt;"
            Next
            MsgBox NewBody
               'Set the HTML body
                objMailItem.HTMLBody = NewBody
                'Display email before sending
                objMailItem.Display
    'Close the If block.
    End If
        Kill Fname
End Sub
</code></pre>

<p>MsgBox NewBody outputs:</p>

<p><a href="https://i.stack.imgur.com/g4JXm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/g4JXm.png" alt="MsgBox NewBody output"></a></p>

<p>and the final email looks like:
<a href="https://i.stack.imgur.com/4C9tN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4C9tN.png" alt="email"></a></p>

<p>It should show all charts one below the other one, however it only takes myChart1.png and repeats it 8 times, despite the output of NewBody.</p>

<p>What am I doing wrong? I'm using Outlook 2013 and Excel 2013</p>

<p><strong>UPDATE:</strong> I added another image and it seems to, in this case, repeat the last image I added 9 times (same as number of attached images). I'm guessing it's a problem with the cid, maybe ids aren't unique? </p>