'How to write a macro that send excel as a pdf to outlook web based not app based

I have a macro that creates a pdf and then send it to outlook to attach as a email but it tries to open the app instead of using the web based version. what code can I use to replace it with? enter image description here



Solution 1:[1]

You need to save the workbook on the disk and then use the file path of the just saved file to add it as an attachment in Outlook. The source of the attachment can be a file (represented by the full file system path with a file name) or an Outlook item that constitutes the attachment. For example:

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

The code for automating Outlook desktop will not work for the browser out of the box.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1