'How to automatically print HTML attachments in outlook 32bit or 64bit
When a customer places an order from the site, an email with an attached file (HTML format) is sent to the management for his order and we want to print it automatically through Outlook, I searched all over the internet but the script I did not find a suitable one for this job.
Can anyone create a VBA Scriptfor Outlook 2016 32bit or Outlook 2019 64bit that can be saved and printed directly when a new email contains an attachment?
I tried many scripts but they did not help me and could not print the HTML file automatically, I made all the necessary settings but the script does not work.
Solution 1:[1]
To handle incoming emails in VBA you can handle the NewMailEx event of the Outlook Application class. The NewMailEx event fires when a new message arrives in the Inbox and before client rule processing occurs. This event fires once for every received item that is processed by Microsoft Outlook. The item can be one of several different item types, for example, MailItem, MeetingItem, or SharingItem. The EntryIDsCollection string contains the Entry ID that corresponds to that item. Use the Entry ID returned in the EntryIDCollection array to call the NameSpace.GetItemFromID method and process the item.
After an item is retrieved you could check the Attachments.Count property and decide whether to print it or not.
To print the content of the incoming email item you can use the MailItem.PrintOut method which prints the Outlook item using all default settings. The PrintOut method is the only Outlook method that can be used for printing.
But to print the attached HTML file you need to save it on the disk first and then call the print verb against the saved file, for example:
Sub PrintFile(FileToPrint as string)
Dim objShell
Set objShell = CreateObject("Shell.Application")
If FileToPrint = "" Then
GoTo MainLoop
Else
Debug.Print FileToPrint
objShell.Namespace(0).ParseName(FileToPrint).InvokeVerb ("Print")
End If
MainLoop:
Debug.Print "No files to print"
End Sub
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 | Eugene Astafiev |
