Solved

Event Item_Add failing

Posted on 2013-01-21
3
218 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

When you have clients or friends from around the world, it becomes a challenge to arrange a meeting or effectively manage your time. This is where Outlook's capability to show 2 time zones in one calendar comes in handy.
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.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
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…

734 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