help please, for some reason I can't get the email to move.
it saves & prints but no errors either.
Code is in ThisOutlookSession.
it saves & prints but no errors either.
Code is in ThisOutlookSession.
JavaScript:
'// use Declare PtrSafe Function with 64-bit Outlook
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
Dim objDestFolder As Outlook.MAPIFolder
Dim objOutlook As Outlook.Application
Dim objNamespace As Outlook.NameSpace
Dim objSourceFolder As Outlook.MAPIFolder
Dim objItem As MailItem
Set colAtts = oMail.Attachments
Set objOutlook = Application
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objSourceFolder = objNamespace.GetDefaultFolder(olFolderDrafts)
Set objItem = objOutlook.ActiveInspector.CurrentItem
Set objDestFolder = objNamespace.Folders("Omar").Folders("Inbox").Folders("Omar1")
'// email address attachment that needs to be saved
If colAtts.Count Then
Select Case oMail.SenderEmailAddress
Case "Omar1@Omar.com"
'// Save attachments to
sDirectory = "C:\omar\Documents\Omar1\"
'// Move Email
objItem.Move objDestFolder '???
Set objDestFolder = Nothing
Case "Omar2@Omar.com"
'// Save attachments to
sDirectory = "C:\Attachments\"
Case "Omar3@Omar.com"
'// Save attachments to
sDirectory = "C:\Attachments\"
Case "Omar4@Omar.com"
'// Save attachments to
sDirectory = "C:\omar\Documents\Omar4\"
Case Else: Exit Sub
End Select
For Each oAtt In colAtts
'// 4 characters including the period.
sFileType = LCase$(Right$(oAtt.filename, 4))
Select Case sFileType
Case "xlsx", "docx", ".pdf", ".doc", ".xls" '// Add additional file types below
sFile = sDirectory & oAtt.filename
oAtt.SaveAsFile sFile
'//print attachements
ShellExecute 0, "print", sFile, vbNullString, vbNullString, 0
End Select
Next
End If
End Sub