PDA

View Full Version : Strange item.Attachments error. Really strange...



adim
03-27-2015, 05:09 PM
Hi there,


I have the following code, that should save a specific Excel file attached to an email. The code is combined with a rule, that trigger this script when an emai lwith a specific subject is received.
The code is triggered, but here comes the strangest error I saw lately: itm.Attachments.Count appear to be zero and obviously the file is not saved! But... if I put a breakpoint on "For each..." line and add itm.Attachments.Count to watch window, it is shown as zero. If I add itm only, then browse to Attachments property, then to Count property it shows 1 for Count (as it should) and the code is executed fine. I spent half a day trying to understand what's going on, but I can't figure it out and I'm on the verge of madness.
The behaviour is the same both on a Outlook 2010 x64 on a Windows 7 x64 and on a Outlook 2010 x86 on a Windows 7 x86. Macros are enabled in Trust Center. I have attached some screenshot with the code and rule settings and also a movie showing the watch windows strangeness.
The script was built some time ago and it worked well on a couple of PCs and it was based on the steps from here: "h**p://iterrors.com/outlook-automatically-save-an-outlook-attachment-to-disk/".
I have tried with and without "this computer only" setting for the rule.
Any ideas?


Adrian


1 min. movie here: "h**tps://drive.google.com/file/d/0Bw-aVIPSg4hsZERQWUJHLXd4bjA/view?usp=sharing"

Rule screen:

13087




Public Sub Kona(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
saveFolder = "C:\test"
For Each objAtt In itm.Attachments
If InStr(objAtt.DisplayName, "Kona Preferred Fixed Price Matrix (ALL)") Then
objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
End If
Set objAtt = Nothing
Next
End Sub


P.S. Apologies to site admins for trying to post links at my first message here, but I really believe they are relevant.

gmayor
03-28-2015, 01:29 AM
Hmmm. Having reproduced your code and e-mail message, I have been unable to reproduce this issue (32bit Outlook 2010 on Windows 7 Ultimate 64 bit). The watch shows a count of 1 as anticipated and the attachment is saved when run to completion. FWIW I think I would have been inclined to modify the macro a tad


For Each objAtt In itm.Attachments
If InStr(objAtt.DisplayName, "Kona Preferred Fixed Price Matrix (ALL)") > 0 Then
objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
End If
Next
Set objAtt = Nothing
But it worked as you had it.

adim
03-28-2015, 05:03 AM
My email account is gmail, added as IMAP in Outlook. Same code and rule combination is working fine in Outlook 2013/Windows 8, on the same email account and directly on my laptop. The non working variants (Outlook 2010 x64 on a Windows 7 x64 and Outlook 2010 x86 on a Windows 7 x86) are both on virtual machines. Maybe this could be a cause of troubles?