Solved

Event Item_Add failing

Posted on 2013-01-21
3
214 Views
Last Modified: 2013-03-07
Hello, every hour I receive 4 emails, each one with a attachment. I need to save the attachment, to save the historical data, and then replace a standard file for this attachment.

The problem I thinks it's going on is that these emails arrive at the exact same time and I guess the macro is losing itself while is running one sub and another email comes in. I've tried with Item_Add Event and with Rules/Alerts linked to a script (I read somewhere it was more reliable). None of those worked.

Is there any workaround for this within the outlook itself? I'd hate to have to make an application just to check the emails and save the attachments.

Here is the code I used (with Rules/Alerts):

Const folderCitiCayman = "M:\MOT-VOFFSHORE\Bases Corretoras\CITI - ITAU BANK"
Const folderCitiNassau = "M:\MOT-VOFFSHORE\Bases Corretoras\CITI - NASSAU"
Const fodlerGSCayman = "M:\MOT-VOFFSHORE\Bases Corretoras\GS - ITAU BANK"
Const folderGSNassau = "M:\MOT-VOFFSHORE\Bases Corretoras\GS - NASSAU"


Sub ProcessCitiNassau(Item As MailItem)
Dim folder As MAPIFolder

Set folder = Application.GetNamespace("MAPI").Folders("Archive").Folders("Futures").Folders("Citi").Folders("Nassau")
Item.Move folder
If Item.Attachments.Count > 0 Then
    For i = 1 To Item.Attachments.Count
        If Split(Item.Attachments(i).Filename, ".")(1) = "csv" Then
            Item.Attachments(i).SaveAsFile folderCitiNassau & "\" & Item.Attachments(i).Filename
            Item.Attachments(i).SaveAsFile folderCitiNassau & "\CITI_NASSAU.csv"
        End If
    Next i
End If
End Sub

Sub ProcessCitiCayman(Item As MailItem)
Dim folder As MAPIFolder

Set folder = Application.GetNamespace("MAPI").Folders("Archive").Folders("Futures").Folders("Citi").Folders("Itau Bank")
Item.Move folder
If Item.Attachments.Count > 0 Then
    For i = 1 To Item.Attachments.Count
        If Split(Item.Attachments(i).Filename, ".")(1) = "csv" Then
            Item.Attachments(i).SaveAsFile folderCitiCayman & "\" & Item.Attachments(i).Filename
            Item.Attachments(i).SaveAsFile folderCitiCayman & "\CITI_ITAUBANK.csv"
        End If
    Next i
End If
End Sub

Sub ProcessGSCayman(Item As MailItem)
Dim folder As MAPIFolder

Set folder = Application.GetNamespace("MAPI").Folders("Archive").Folders("Futures").Folders("Goldman Sachs").Folders("Itau Bank")
Item.Move folder
If Item.Attachments.Count > 0 Then
    For i = 1 To Item.Attachments.Count
        If Split(Item.Attachments(i).Filename, ".")(1) = "xls" Then
            Item.Attachments(i).SaveAsFile folderGSCayman & "\" & Item.Attachments(i).Filename
            Item.Attachments(i).SaveAsFile folderGSCayman & "\GS_ITAUBANK.xls"
        End If
    Next i
End If
End Sub

Sub ProcessGSNassau(Item As MailItem)
Dim folder As MAPIFolder

Set folder = Application.GetNamespace("MAPI").Folders("Archive").Folders("Futures").Folders("Goldman Sachs").Folders("Nassau")
Item.Move folder
If Item.Attachments.Count > 0 Then
    For i = 1 To Item.Attachments.Count
        If Split(Item.Attachments(i).Filename, ".")(1) = "xls" Then
            Item.Attachments(i).SaveAsFile folderGSNassau & "\" & Item.Attachments(i).Filename
           Item.Attachments(i).SaveAsFile folderGSNassau & "\GS_NASSAU.xls"
        End If
    Next i
End If
End Sub

Open in new window


Thanks in advance.
0
Comment
Question by:toddinho
  • 2
3 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 38806625
Hi, toddinho.

it shouldn't make any difference that the items all arrive at once.  Outlook makes a call to the macro for each item.  Are you saying that the macro isn't being called, or is it that the macro is being called but isn't working the way you expected?
0
 

Author Comment

by:toddinho
ID: 38816168
Yes, I dont know whether Outlook run the macros in separated threads or in the same one, but it seems like when a message arrives and it's still running the macro for the last one, the trigger for Item_Add is lost and it doesnt run the macro for it...
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 38839066
If you're calling the macro from a rule, then Item_add doesn't come into play.

How about adding some debugging statements to see what's going on?
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
Check out this infographic on what you need to make a good email signature that will work perfectly for your organization.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now