Print Attachments from another mailbox (not default)

Status
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.

Thanks.

Michael.

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
Next
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
 

Michael Honey

New Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server
In addition to the Set folder line in startup, you need to use getfolderpath function to set another object
http://www.slipstick.com/developer/working-vba-nondefault-outlook-folders/

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.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
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
S Cannot print PDF attachments from Outlook mail Using Outlook 1
R I am unable to print emails with attachments and also without attachments from sent & inbox of my ou Using Outlook 1
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
M Custom Calendar Print Suggestions? Using Outlook 0
A Day view - print appointment details Calendar Printing Assistant 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 New Slipstick.com Articles 0
Diane Poremsky Combine and Print Multiple Outlook Calendars New Slipstick.com Articles 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 New Slipstick.com Articles 0
Diane Poremsky No drop down calendars in Outlook 2010 Print Options New Slipstick.com Articles 0
Diane Poremsky Print Monthly or Work Week Calendars New Slipstick.com Articles 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 Calendar Printing Assistant 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
E Can't print from Outlook on wifi network Using Outlook 0
E can't print some retail discount coupons Using Outlook 7
J calendar print setup in outlook 2010 Calendar Printing Assistant 1
D Use Outlook 2003 embedded imaged cannot print from the mail preview list Using Outlook 4
J Print next 7 days view of calendar (2010) Using Outlook 3
C Print all emails in a single folder with sent items Using Outlook 2
P Outlook closes down after clicking on the quick print icon. Using Outlook 3
I Outlook 2010 Print Created Date on Drafts Using Outlook 3
P Print multiple pocket calendars on one page Using Outlook 5

Similar threads

Top