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. 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: http://ift.tt/1I0YvWl. Any ideas?
Adrian
Rule screen here: http://ift.tt/1I0Ythe
Movie here: http://ift.tt/1I0Ythg
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
Aucun commentaire:
Enregistrer un commentaire