Print Attachments from another mailbox (not default)

Not open for further replies.

Michael Honey

New Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server
Hi guys,

I have a macro below which works perfectly fine, but only my the default mailbox (Mailbox - Michael Honey). It automatically prints attachments as mail arrives into my inbox that have a pdf attachment only.

I understand the macro works, but just need to know how to access another mailbox (2nd mailbox called JMAP Remittance). I have more than one mailbox in my Outlook.

How can I change the Ns Object to look at a different mailbox other than the default.

I can do things like msgbox Ns.folders(1).Name and it shows the JMAP Remittance mailbox name, but I can't set it as an object so that I can access all the email Items.

If you can offer some advice as how I can set the object to the other mailbox account I would greatly appreciate it.



Code Below:

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Private WithEvents Items As Outlook.Items

Private Sub Application_Startup()

Dim Ns As Outlook.NameSpace
Dim Folder As Outlook.MAPIFolder

Set Ns = Application.GetNamespace("MAPI")
Set Folder = Ns.GetDefaultFolder(olFolderInbox)
Set Items = Folder.Items

End Sub

Private Sub Items_ItemAdd(ByVal Item As Object)
If TypeOf Item Is Outlook.MailItem Then
PrintAttachments Item
MovePrintedMail Item
End If
End Sub

Private Sub PrintAttachments(oMail As Outlook.MailItem)
On Error Resume Next
Dim colAtts As Outlook.Attachments
Dim oAtt As Outlook.Attachment
Dim sFile As String
Dim sDirectory As String
Dim sFileType As String
sDirectory = "c:\Attachments\"
Set colAtts = oMail.Attachments
If colAtts.Count Then
For Each oAtt In colAtts
' This code looks at the last 4 characters in a filename
sFileType = LCase$(Right$(oAtt.FileName, 4))
Select Case sFileType
' Add additional file types below
Case ".pdf"
sFile = sDirectory & oAtt.FileName
oAtt.SaveAsFile sFile
ShellExecute 0, "print", sFile, vbNullString, vbNullString, 0
End Select
End If
End Sub

Sub MovePrintedMail(oMail As Outlook.MailItem)

Dim objDestFolder As Outlook.MAPIFolder
Set objDestFolder = Session.Folders("Mailbox - Michael Honey").Folders("Inbox").Folders("Printed")
oMail.Move objDestFolder
Set objDestFolder = Nothing

End Sub
In addition to the Set folder line in startup, you need to use getfolderpath function to set another object

then copy the items.add macro, using the second folder object.

I'd probably use
Set mInbox = Ns.GetDefaultFolder(olFolderInbox).items
Set sInbox = Getfolderpath("JMAP Remitance\Inbox").items
in application startup, instead of two lines for each folder object.

Thanks so much for your help that worked perfectly.
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
G Print email attachments when hit subfolder Outlook VBA and Custom Forms 1
P Print attachments automatically and move the mail to an existing folder called "Ted" Outlook VBA and Custom Forms 4
M Print email and, attachments sent in hyperlinks in the email Outlook VBA and Custom Forms 2
D Print attachments automatically and moves the mail to a new folder Outlook VBA and Custom Forms 9
D Print Attachments only in selected emails using a macro Outlook VBA and Custom Forms 3
I Print Automatically Attachments Outlook VBA and Custom Forms 3
J Auto print PDF attachments as they arrive with certain words in subject Outlook VBA and Custom Forms 3
C automatically print attachments Using Outlook 4
O For Outlook 2007 - VBA to print attachments Using Outlook 1
J Outlook 2010 using Quick Print to print attachments Using Outlook 1
A Outlook 11 for Mac won't print e-mail attachments Using Outlook 6
5 Automatically print email attachments Using Outlook 7
P Possible to write a macro to print all attachments with specific . Outlook VBA and Custom Forms 1
Z Re: Auto Print email and word attachments on send Outlook VBA and Custom Forms 1
U Outlook not responding when trying to print Emails Using Outlook 6
D VBA Macro to Print and Save email to network location Outlook VBA and Custom Forms 1
S Cannot print Contacts Using Outlook 7
G print attachment straight away; working script edit not working Outlook VBA and Custom Forms 0
S CONTACT FIELD PRINT ORDER Outlook VBA and Custom Forms 1
A VBA Script - Print Date between first email in Category X and last email in Category Y Outlook VBA and Custom Forms 3
B Outlook 2016 Outlook crashes when trying to print certain emails Using Outlook 5
M Batch print without appended trail of repeated e Using Outlook 2
Witzker print-list-of-outlook-folders with sort posibility Outlook VBA and Custom Forms 7
M Custom Calendar Print Suggestions? Using Outlook 0
A Day view - print appointment details Using Outlook 1
I print calendar without subject and details Using Outlook 1
oliv- property "is printed" or catching print events Outlook VBA and Custom Forms 2
Diane Poremsky Print a list of your Outlook folders Using Outlook 0
Diane Poremsky Combine and Print Multiple Outlook Calendars Using Outlook 0
B Print list of previously sent recipients Using Outlook 1
R Print email message and attachment in order Outlook VBA and Custom Forms 2
L Outlook 2002: HTML Emails Will Not Print: Please Help Using Outlook 0
A Print first page of a new email Outlook VBA and Custom Forms 7
Diane Poremsky Print Monthly or Work Week Calendars Using Outlook 0
Diane Poremsky No drop down calendars in Outlook 2010 Print Options Using Outlook 0
Diane Poremsky Print Monthly or Work Week Calendars Using Outlook 0
S Macro to print & move selected emails? Using Outlook 3
H Problems With Outlook 2013 VBA To Send and Print an email Outlook VBA and Custom Forms 1
D Outlook 2013 Categories won't print In color Using Outlook 2
G Calendar monthly view - Print just 3 weeks Using Outlook 5
R Can't modify Outlook view font with IE anymore (even though IE still affects print font) Using Outlook 5
E Outlook VBA to print attached Pdf to a fax printer and assign fax number Using Outlook 0
L Outlook 2010 Quick Print Attachment, nothing happend Using Outlook 0
J Automatically Print PDF When They Are Received Using Outlook 4
M button to send and print emails Using Outlook 26
S How to print ONLY first line of appointments in month view? Using Outlook 1
M print free/busy schedule of an user Using Outlook 2
W Cannot print Outlook 2007 emails Using Outlook 2
R problem with incomming e-mail I am unable to print full e-mail letter Using Outlook 1
M Custom print contacts Using Outlook 2

Similar threads