Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Event Item_Add failing

Posted on 2013-01-21
3
Medium Priority
?
222 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 1500 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
Mailbox Corruption is a nightmare every Exchange DBA wishes he never has. Recovering from it can be super-hectic if not entirely futile. And though techniques like the New-MailboxRepairRequest cmdlet have been designed to help with fixing minor corr…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

824 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