Quantcast
Channel: All OutlookCode.com content
Viewing all articles
Browse latest Browse all 871

Need a bit of help with handling attachments

$
0
0
Hello, I come to this site in search of an answer that seems to be beyon my reach. I have been requested to create a script that will parse each new email that comes in a specific mailbox and forward those with a specific attachment *name* to another email account. So far, i managed to several examples of code. One of them was supposed to do just that : 'code goes in "ThisOutlookSession" module Private Sub Application_NewMailEx(ByVal EntryIDCollection As String) Dim arr() As String Dim i As Integer Dim ns As Outlook.NameSpace Dim itm As MailItem Dim m As Outlook.MailItem Dim att As Outlook.Attachment On Error Resume Next Set ns = Application.Session arr = Split(EntryIDCollection, ",") For i = 0 To UBound(arr) Set itm = ns.GetItemFromID(arr(i)) If itm.Class = olMail Then Set m = itm If m.Attachments.Count > 0 Then For Each att In m.Attachments If UCase(att.FileName) Like "*REPORT*" Then MoveToFolder m, "MoveTest" Exit For End If Next att End If End If Next Set ns = Nothing Set itm = Nothing Set m = Nothing End Sub Sub MoveToFolder(mItem As MailItem, folderName) '###you need to edit this for your account name### Const mailboxNameString As String = "Mailbox - firstname lastname" Dim olApp As New Outlook.Application Dim olNameSpace As Outlook.NameSpace Dim olDestFolder As Outlook.MAPIFolder Set olNameSpace = olApp.GetNamespace("MAPI") Set olDestFolder = olNameSpace.Folders(mailboxNameString).Folders(folderName) Debug.Print "[" & Date & " " & Time & "] " & _ ": folder = " & folderName & _ "; subject = " & mItem.Subject & "..." mItem.Move olDestFolder End Sub Placing that in ThisOutlookSession plain doesn't work (i updated mailboxnamestring). I don't know what i'm doing wrong - i haven't got any kind of feedback as to where does it hang or if it runs or not. What would i have to modify for this to be able to be saved as a macro/script, so that i can make it part of a rule? what am i doing wrong? Thanks in advance! AP

Viewing all articles
Browse latest Browse all 871

Trending Articles