Consulting

Results 1 to 3 of 3

Thread: Strange item.Attachments error. Really strange...

  1. #1
    VBAX Newbie
    Joined
    Mar 2015
    Posts
    2
    Location

    Strange item.Attachments error. Really strange...

    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:

    rule.jpg


    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.
    Last edited by adim; 03-27-2015 at 05:20 PM. Reason: apologies

  2. #2
    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.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Newbie
    Joined
    Mar 2015
    Posts
    2
    Location
    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •