2

I use this https://stackoverflow.com/a/48897439/14866652 to a range as an image into an Outlook email.

I don't want the screen to display so I changed the .Display to .Send. The mail is sent empty:

Public Sub enviarmail()
    Dim rng As Range
    Dim olApp As Object
    Dim Email As Object
    Dim Sht As Excel.Worksheet
    Dim wdDoc As Word.Document
    
    Set Sht = ActiveWorkbook.Sheets("Cierre de ventas")
    Set rng = Sht.Range("B23:N35")
    rng.CopyPicture Appearance:=xlScreen, Format:=xlPicture
    
    With Application
        .EnableEvents = False
        .ScreenUpdating = False
    End With
    
    Set olApp = CreateObject("Outlook.Application")
    Set Email = olApp.CreateItem(0)
    Set wdDoc = Email.GetInspector.WordEditor
    
    With Email
        .BodyFormat = 2
        .To = Range("D13").value
        .CC = Range("D14").value
        .Subject = Range("D15").value
           
        wdDoc.Range.PasteAndFormat Type:=wdChartPicture
        wdDoc.Range.InsertAfter vbLf & vbLf & "Firmado: " & Range("K13").value
 
        With wdDoc
            .InlineShapes(1).Height = 260
        End With
  
        .Send
            
    End With
    
    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With
    
    Set Email = Nothing
    Set olApp = Nothing
   
End Sub

Update: after several tests, @urdearboy's Potential Workaround #2 works, no need to use a buffer too, I've tried before without the buffer and I did not got it to work.

Using .Display and .Send at the same time works.

0m3r
  • 12,286
  • 15
  • 35
  • 71

1 Answers1

2

Potential Workaround #1

I've ran into a similar issue that only occurs when adding objects to body outside of text or a direct file upload. The only way I have been able to solve is to add a time buffer between the file being added and the email being sent.

I know the answer here is not satisfying, but worth a try:

Application.Wait Now + #12:00:01 AM#
.Send

Here is the question I posted with issue. I bountied this and still got no solution so settled with the time delay eventually


Potential Workaround #2

You can also try to first display and then send email. Same as above, this seems like a workaround to the actual problem but may be worth a try. If you are just sending one email then this could be a acceptable route to go. If many, then it may slow down the process and become less ideal.

With Email

    'Email Attributes
    .Display
    .Send

End With
urdearboy
  • 14,439
  • 5
  • 28
  • 58
  • Thank you @urdearboy, I havent think of that, sadly, I get same output, an empty email. – Francisco J Pérez Dec 21 '20 at 17:12
  • 1
    I've placed it in several and different spots, tried with +3 seconds and sadly same issue. I've tried also in a different PC but it remains the same. Thank you for your persistence. – Francisco J Pérez Dec 21 '20 at 17:23
  • Wonder if you can display email and then send it. Still feels like a workaround to the actual problem but curious if that works – urdearboy Dec 21 '20 at 17:27
  • 1
    you got it right!! I've previously tried .display and .send with no results but, adding a buffer and using them both together did work! So, the solution is : Application.Wait Now + #12:00:01 AM# .Display .Send Thank you one more time – Francisco J Pérez Dec 21 '20 at 17:32
  • lol surprised to hear both are needed to get this to work. Still curious to know if there is a way to directly address the issue rather using workarounds that I shared. I would not be offended if you didn't accept my solution to see if anyone comes in with a better solution – urdearboy Dec 21 '20 at 17:33