0

I am trying to send an email, with a chart, using VBA in Excel.

When I use .Display the email is created with that picture (chart) inside the email and it is sending.
When I sending straight away using .Send, the picture of the chart disappears from the email.

Also, I would like to better understand parameters after using:

.Attachments.Add PicFilename, 1, 1

What are the numbers "1, 1" which I took from one of the examples on website.

Community
  • 1
  • 1
Robert
  • 1
  • 1
  • These examples https://stackoverflow.com/questions/44869790/embed-picture-in-outlook-mail-body-excel-vba, https://stackoverflow.com/questions/38905847/embedding-image-in-outlook-with-vba and https://stackoverflow.com/questions/55941325/embedding-an-html-file-with-images-in-an-outlook-email-generated-by-excel-vba all use `.Display` then `.Send`. If not acceptable, for instance in bulk mail scenario, you may need to investigate a non-VBA solution. – niton Mar 15 '21 at 20:22
  • Documentation: https://learn.microsoft.com/en-us/office/vba/api/overview/outlook/object-model – niton Mar 15 '21 at 20:22

1 Answers1

0

The Attachments.Add method is described in MSDN.

Sub AddAttachment() 
 Dim myItem As Outlook.MailItem 
 Dim myAttachments As Outlook.Attachments 
 
 Set myItem = Application.CreateItem(olMailItem) 
 Set myAttachments = myItem.Attachments 
 myAttachments.Add "C:\Test.doc", _ 
 olByValue, 1, "Test" 
 myItem.Display 
End Sub

Try to save the item before sending it out. Also you can use two calls sequentially if it helps:

mailItem.Display(False)
mailItem.Send()
Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45