Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Event Item_Add failing

Posted on 2013-01-21
3
Medium Priority
?
220 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 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 learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

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.
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
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 …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

715 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