An Outlook user had a request to print sent messages automatically:
I want to send and then print the sent emails with a click of the button.
He had some VBA code, however it wasn't working for him due to a couple of errors. I helped him fix it and this is what he ended up with. If you just want to create a button for a category (instead of using the Category picker), you only need the SendPrint() code.
Note that the category name is case-sensitive.
To use, set your macro security to low. Add this code to ThisOutlookSession, create a ribbon or QAT button for the SendPrint macro. To test it without restarting Outlook, click in Application_Startup and then click Run. For more information, see How to use Outlook's VBA Editor
After composing your message, click your button to send and print the message instead of using the Send button.
Send and Print
Option Explicit Private WithEvents Items As Outlook.Items Private Sub Application_Startup() Set Items = Session.GetDefaultFolder(olFolderSentMail).Items End Sub Private Sub Items_ItemAdd(ByVal Item As Object) If Item.Categories = "Print" Then Item.PrintOut End If End Sub Sub SendPrint() Dim obj Set obj = ActiveInspector.CurrentItem obj.Categories = "Print" obj.Send End Sub
Remove category and print
To remove the category from the item after its printed (so you know which messages were printed), replace the ItemAdd macro above with this code.
Private Sub Items_ItemAdd(ByVal Item As Object) If Item.Categories = "Print" Then Item.Categories = "" Item.PrintOut End If End Sub
I have a related autoprint macro that prints an email when it is moved to a specified folder. It does work, but the Private Sub Application_Startup() is not being run when Outlook starts. Any idea what's causing this issue? Thanks for your help.
Option Explicit
Public WithEvents objSpecificFolder As Outlook.Folder
Public WithEvents objItems As Outlook.Items
Private Sub Application_Startup()
'https://www.datanumen.com/blogs/auto-print-email-moved-specific-folder-outlook/
'Specify the folder
'You can change it as per your needs
Set objSpecificFolder = Application.Session.GetDefaultFolder(olFolderInbox).Folders("Daily Risk")
Set objItems = objSpecificFolder.Items
End Sub
Private Sub objItems_ItemAdd(ByVal Item As Object)
'Macro works when new item lands into the specific folder
'https://www.datanumen.com/blogs/auto-print-email-moved-specific-folder-outlook/
Dim objMail As Outlook.MailItem
If TypeOf Item Is MailItem Then
Set objMail = Item
objMail.PrintOut
End If
End Sub
Also, using windows 10 and office 2016
If the macro is working, then the AutoStart macro is running.
Or are you going in to the VB Editor to run it after outlook loads? If so, what are your macro security settings?
As an FYI, i use this macro to run the auto start macro if i think it died -
Sub RunStart()
Call Application_Startup
MsgBox "App Start Started"
End Sub
The Application_Startup() macro only runs when I manually trigger it in the VBE editor. I'm trying to figure out why it's not actually running wen the application starts. My macro settings are Enable all macros (not recommended....) and the "Apply macro security settings to installed add-ins" is checked. Thank you, any thoughts are highly appreciated.
what type of email account? I've seen this behavior with IMAP accounts - the folders aren't loaded when the macro kicks in. Do you get any error messages?
Hi , I know this question was written back in 2013 but are you able to help me with a macro that will print a sent email that was directed (via rules) to particular folder in outlook. For example when I send my email it automatically goes toe a folder named - "PRT Pmt Notifications" once this has been sent I want it to print. The description in the body is "Please see below payment for Payroll Tax" Many thanks
The macro is looking for new messages added to the sent folder:
Set Items = Session.GetDefaultFolder(olFolderSentMail).Items
what you change the line to depends on where the folder is, but assuming it's at the same level as the sent folder and inbox, you'd use this to watch the folder
Set Items = Session.GetDefaultFolder(olFolderSentMail).Parent.Folders("Pmt Notifications").Items
more info here: https://www.slipstick.com/developer/working-vba-nondefault-outlook-folders/
if you only need to print certain messages, use an if statement to find them
if instr(1,item.body,"Please see below payment for Payroll Tax") > 0 then
' do the print
end if