Hello everyone,
I need help on the following Micro, it works but I need to add a second email address that needs to be saved in same directory and print as they arrive. Thank you
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
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
' Save attachments to
sDirectory = "C:\Attachments\"
Set colAtts = oMail.Attachments
' email address attachment that needs to be saved
If colAtts.Count And oMail.SenderEmailAddress ="email address here" Then
For Each oAtt In colAtts
'The code looks at the last 4 characters,
'including the period and will work as long as you use 4 characters in each extension we want to check.
sFileType = LCase$(Right$(oAtt.FileName, 4))
Select Case sFileType
' Add additional file types below
Case "xlsx", "docx", ".pdf", ".doc", ".xls"
sFile = sDirectory & oAtt.FileName
oAtt.SaveAsFile sFile
'Print saved attachements
ShellExecute 0, "print", sFile, vbNullString, vbNullString, 0
End Select
Next
End If
End Sub