Search code examples
vbaoutlookoutlook-2010

Auto download attachment from Outlook 2010 to local or network folder using Inbox Rules


I have this piece of code, it works on one computer Outlook 2010 64bit but does not work on another machine running 32bit. I do not think this has anything to do with 32bit/64 but just want to mention it in-case.

I have tried everything, disable macro, turning Outlook inside out and cannot get this code to work.

Maybe a second eye will find something I am missing:

Sub saveAttachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
Dim dateFormat
dateFormat = Strings.Format(Now(), "mm_dd_yyyy_HH_MM_SS_AMPM")
saveFolder = "C:\Users\Jarvis\Desktop\Test"
For Each objAtt In itm.Attachments
objAtt.SaveAsFile saveFolder & "\" & "My_Data_" & dateFormat & ".csv"
Set objAtt = Nothing
Next
End Sub

Thanks everyone!


Solution

  • Based on our chat, it seems the solution was to:

    1. Copy EVERYTHING out of your VB macro project, into a text file. Save the textfile to your drive.
    2. Close everything, reboot the computer.
    3. Go to your C:\Documents and settings<yourusernamehere>\Application Data\Microsoft\Outlook folder.
    4. Either delete the file VBAProject.otm, or (better and safer) rename to VBAProject.old or some similar name.
    5. Open Outlook
    6. Reopen the VB Macro editor
    7. Paste in the code from your text file.

    [Instructions courtesy of Arcane Code]