Excel -> Outlook embedded image

ReeveCZE

New Member
Joined
Jun 8, 2014
Messages
7
Hi guys,

I'm having some hard time with the following.
I have a For - Next loop in Excel that generates an Outlook MailItem drafts with embedded image using ContentID.

Code:
Dim outApp as Object
Dim outMail as Object

Set outApp = CreateObject("Outlook.Application")  
    
    For i '..... blah blah some logic
    
        Set outMail = outApp.CreateItem(0)
        
        With outMail
            .SentonBehalfofName = "something@gmail.com"
            .BodyFormat = 2 'HTML format
            .To = "something@gmail.com"
            .Subject = "something"
[COLOR=#ff0000]            .Attachments.Add "C:\wm_logo.png", olByValue, 0 'aka create a copy of the file and hide it[/COLOR]
            .HTMLBody = "something" & "img src=""cid:wm_logo.png"">" 'I'm ommiting the < intentionally :-D
            .GetInspector 'otherwise I get "The linked image cannot be displayed" frame with red cross...
            .Close olSave
        End With
        
        Set outMail = Nothing
    Next i

Set outApp = Nothing

Works perfectly but the procedure always crashes when generating the 200th mail at the Attachments.Add with the following:
T6IF.png


Any ideas? Is there any limit for attachments in drafts? :-D
When I manually create a new mail in Outlook after this error and try to attach the same image file, I get the same error.
When I copy the image file, rename it and try to attach the renamed copy, it works.
When I restart Outlook, manually create a new mail in Outlook and try to attach the same image file, it works.

I know I could use a signature from AppData, but let's assume I can't and I'm forced to "create" my own signature.
Thanks in advance, I'm kinda lost
 
Last edited:

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
After some investigaiton I found out the problem is .GetInspector.
If I comment that line I can generate 600 mails with attachments and embedded images, however, the image is not displayed properly.
Am I closing the Inspector in a wrong way? It seems to me I'm not allowed to have more than 200 Inspectors open :)
 
Upvote 0
Well, there seems to be a difference between MailItem.Close and MailItem.GetInspector.Close.
I'm afraid I don't understand it exactly, but the the following works:
Code:
With outMail
    .SentonBehalfofName = "something@gmail.com"
    .BodyFormat = 2 'HTML format
    .To = "something@gmail.com"
    .Subject = "something"
    .Attachments.Add "D:\X_Temporary\Kanta_Ondrej\wm_logo.png", olByValue, 0
    .HTMLBody = bodyString & chr(60) & "img src=""cid:wm_logo.png"">"
[COLOR=#008000][B]    .GetInspector.Close olSave[/B][/COLOR]
End With

If someone is able to explain the difference, I'm eager to know. ;)
 
Upvote 0

Forum statistics

Threads
1,223,677
Messages
6,173,781
Members
452,534
Latest member
autodiscreet

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