Windows 10
Microsoft 365
Outlook v.2205
I am writing a macro that prints the selected email AND attachments to PDF. I need this to be fully automatic, without any user intervention once the macro starts. The problem I have, is that when the mailItem.PrintOut command is used, a print dialogue window appears and freezes the macro until the user advances the window manually.
I am able to cobble together the body of the email using the Word object library where I can easily print, but for email attachments (such as PDFs) I am at a loss.
I have scoured the web looking for a solution to this. I have found nothing so far that can be done in pure native VBA.
Image of the printer dialogue that I would like to bypass:
I previously asked here whether it is possible to manipulate the printer dialogue window using API/VBA code, but later realized that once the printer dialogue appears, VBA stops working so I must find a way to bypass the dialogue window altogether.
It seems unlikely to me that there does not exist a way to do this.
Code posted below (simplified for reference):
Private Sub printEmail()
Dim mySelection As Outlook.Selection
Dim myEmail As MailItem
Set mySelection = Application.ActiveExplorer.Selection
' If item = mailitem, print
If mySelection.Item(1).Class = 43 Then
Set myEmail = mySelection.Item(1)
myEmail.PrintOut ' <===###this command causes a dialogue to appear###
' Else, exit sub
Else
MsgBox "Select a mail item"
Exit Sub
End If
End Sub