-2

I am trying to create an Outlook email draft with an inline pdf document.

I managed to add inline pictures using html img src tag but this does not work for documents. What should I modify to add pdf instead of images?

I tried using the position but does not add in the correct position instead adds to the end of text.

Set outlook = createObject(“Outlook.Application”)
Set mailItem = outlook.CreateItem(olMailItem)

With mailItem
    .BodyFormat = olFormatRichText
    .Body = “hello world”
    .Attachments.add “file.pdf”, olByValue, 6
End With
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Zavfel
  • 39
  • 1
  • 8
  • Is this what your trying to do? https://stackoverflow.com/a/44599739/4539709 – 0m3r Dec 31 '18 at 18:17
  • @0m3r yes, that's what I am trying to do but position the icon in-between text, turns the fix to my code is to bring the attachments.add outside the with clause for this to work. I still don't get why am I being down voted since this is a legit question. – Zavfel Jan 01 '19 at 15:46
  • @Storax this is possible to do within outlook itself and is not necessary to use a third party library/app. you can do so by select richtext and I am trying to replicate this with VBA instead. – Zavfel Jan 01 '19 at 15:48
  • @Zavfel: If it's possible it would be great you shared your code because I still think you cannot embed a PDF.file inline like in a webbrowser for example. – Storax Jan 01 '19 at 16:01
  • @storax I think you misunderstood my question, I am trying to add them inline as an icon as shown in the link provided by 0m3r. By bringing the add function out of the with clause will add the pdf at the correct position but it enlarges it, I am trying to fix it before posting it as a correct answer – Zavfel Jan 01 '19 at 16:11
  • @Zavfel: Yes, sorry, then I got you totally wrong. But 0m3r provided a link with a solution then or at least an approach, right? – Storax Jan 01 '19 at 16:14
  • https://stackoverflow.com/a/49104427/4539709 – 0m3r Jan 04 '19 at 00:30
  • https://stackoverflow.com/a/48897439/4539709 – 0m3r Jan 04 '19 at 00:31

2 Answers2

0

You can only do that in the RTF format, not in HTML. When calling MailItem.Attachments.Add, specify the Position parameter appropriately.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • Do you know how to add multiple attachments? using the add seem to add the 2nd or more document at the first document's index – Zavfel Jan 10 '19 at 16:52
  • Do you specify the same index when calling Add for multiple attachments? – Dmitry Streblechenko Jan 10 '19 at 17:23
  • you can ignore this, I realised you have to specify the index backwards for it to work, I have been trying to add the attachment index in order. e.g. add position 2, add position 4 which does not work. – Zavfel Jan 10 '19 at 17:24
0

It seems like the add function only works after you call display, else it will only add to the end of the entire body

Set outlook = createObject(“Outlook.Application”)
Set mailItem = outlook.CreateItem(olMailItem)

With mailItem
    .BodyFormat = olFormatRichText
    .Body = “hello world”
    .Display
    .Attachments.add “file.pdf”, olByValue, 6
End With
Zavfel
  • 39
  • 1
  • 8