Results 1 to 3 of 3

Thread: Excel -> Outlook embedded image
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Jun 2014
    Posts
    7
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Excel -> Outlook embedded image

    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"
                .Attachments.Add "C:\wm_logo.png", olByValue, 0 'aka create a copy of the file and hide it
                .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:


    Any ideas? Is there any limit for attachments in drafts?
    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 by ReeveCZE; Jun 21st, 2019 at 07:39 AM.

  2. #2
    New Member
    Join Date
    Jun 2014
    Posts
    7
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Excel -> Outlook embedded image

    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

  3. #3
    New Member
    Join Date
    Jun 2014
    Posts
    7
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Excel -> Outlook embedded image

    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"">"
        .GetInspector.Close olSave
    End With
    If someone is able to explain the difference, I'm eager to know.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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