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

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
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,224,820
Messages
6,181,162
Members
453,021
Latest member
Justyna P

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