Reputation: 732
I'm trying to attach a Onedrive file link to an Outlook email. This is not the same as the .Attachments.Add method, where the file gets attached as a copy. The file needs to be shared as a link that the recipients can edit. This can be done manually, but trying to automate for a large number of emails to be sent this way.
Upvotes: 1
Views: 2619
Reputation: 732
After some testing using existing emails, I found the Attachment type for a linked file is a value of 7. Using the usual method of .Attachments.Add you can specify the type to be 7 and that attaches the file as a link rather than a copy of the online file. This should work whether it is a Onedrive/Sharepoint/Teams file.
Set OutApp = CreateObject("Outlook.Application")
Set OutlookItem = OutApp.CreateItemFromTemplate(*EmailTemplate*)
OutlookItem.Attachments.Add *FileFullOnlinePath*, 7
OutlookItem.Display
Note that the Microsoft VBA online reference shows only the following types.
https://learn.microsoft.com/en-us/office/vba/api/outlook.olattachmenttype.
The attachment type 7 is not mentioned here. If anyone has more information, please share.
Upvotes: 3