Solved

Event Item_Add failing

Posted on 2013-01-21
3
217 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Exchange/Outlook 2010 Calender conflict 6 49
Export Outlook 'ghost contacts' 11 40
Using an iCal Calendar Subscription in Outlook 4 33
Outlook 2016 10 46
Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

696 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