
Step 1: Open your Outlook and enable micro.
File>>Option>> Trust Center>> Trust center settings>> Select notification for all macros
Step 2: Then press Alt+F11 to open VBA. Go to ‘Module’ from left panel or you can add one new one if you don’t see it there.
Step 3: Paste the below code and save it.
Public Sub SaveAutoAttach(item As Outlook.MailItem) Dim object_attachment As Outlook.Attachment Dim saveFolder As String ' Folder location when I want to save my file saveFolder = "D:\Data\Archive" For Each object_attachment In item.Attachments ' Criteria to save .doc files only If InStr(object_attachment.DisplayName, ".doc") Then object_attachment.SaveAsFile saveFolder & "\" & object_attachment.DisplayName End If Next End Sub
Step 4: Now Go to Rule>>Manage Rules & Alerts. Please follow below snapshots.
Step 5: Select ‘Apply rule on message I receive’ and Next
Step 6: In this step choose your words sincerely. Right now I am choosing 2nd option. Whatever you select on the first panel you will see them in 2nd panel. Click on ‘Specific word’ circled in the image.
Step 7: Provide the word like “IBM Data” and save it. You can add more words as well.
Step 8: In this step we will select ‘Action’. As we want to run a VBA script, we select ‘run a script’. Again click on ‘run a script’; a pop-up windows may open. Just ‘Enable’ the micros and select the micro which we saved in backend.
Step 9: You are almost done. Save the rule as per your convenience and click ‘Finish’. Select the circled check box if you want to run the script on deleted items otherwise it’s good.
Step 10: Restart your outlook and send some document with subject ‘IBM Data’ and see the magic.
Hi I have pasted the above code in outlook module & when i setting rule, i am not getting open of “Run a script”.
how can i find it, let me know if there is any option to show it.
Hi Bharat,
I am getting the same issue. Did you get a solution?
Hi Bharat,
I am facing the same issue. Did you get a solution for the same?
I ran into the same problem. This link fixed it for me.
https://www.extendoffice.com/documents/outlook/4640-outlook-rule-run-a-script-missing.html
hi, i was curious on how the code would fit ( InStr ) if you wanted to have it for more than two file extenstions.
Like .xlsx or .pdf along with .doc put in.
This is working pefect – thanks for the posting
Hi,
I am not getting the option of run a script in step 8.
What shall I do to correct this issue?
Thanks and Regards
Saurav Vats
email: sauravvats1995@gmail.com
Hi,
I am not able to find the option of run a script (step 8). Can anyone help me with this?
For those of you who don’t see the ‘run a script’ option. Try this: https://www.extendoffice.com/documents/outlook/4640-outlook-rule-run-a-script-missing.html
Thank you so much for instruction auto saving attachments from outlook to specific folder. Such a time saver.
Just one more thing how can i add several other criteria to same VBA project or create a new project?
very useful code, but i have problem
problem is file send with same file name so old file deleted and replaced by new one.
need to add date for file name
thanks for you
try this:
Public Sub SaveAutoAttach(item As Outlook.MailItem)
Dim object_attachment As Outlook.Attachment
Dim FileName As String
Dim saveFolder As String
‘ Folder location when I want to save my file
saveFolder = “D:\Data\Archive”
For Each object_attachment In item.Attachments
‘ Criteria to save .pdf files only
If InStr(object_attachment.DisplayName, “.pdf”) Then
FileName = Replace(object_attachment.DisplayName, “.pdf”, “”)
object_attachment.SaveAsFile saveFolder & “\” & FileName & ” ” & Format(Now(), “DD-MMM-YYYY hh mm AMPM”) & “.pdf”
End If
Next
End Sub
Try this:
Public Sub SaveAutoAttach(item As Outlook.MailItem)
Dim object_attachment As Outlook.Attachment
Dim FileName As String
Dim saveFolder As String
‘ Folder location when I want to save my file
saveFolder = “D:\Data\Archive”
For Each object_attachment In item.Attachments
‘ Criteria to save .pdf files only
If InStr(object_attachment.DisplayName, “.pdf”) Then
FileName = Replace(object_attachment.DisplayName, “.pdf”, “”)
object_attachment.SaveAsFile saveFolder & “\” & FileName & ” ” & Format(Now(), “DD-MMM-YYYY hh mm AMPM”) & “.pdf”
End If
Next
End Sub
Ahmed, i had the same problem. I found that this worked for me:
Public Sub SaveAutoAttach(item As Outlook.MailItem)
Dim object_attachment As Outlook.Attachment
Dim FileName As String
Dim saveFolder As String
‘ Folder location when I want to save my file
saveFolder = “D:\Data\Archive”
For Each object_attachment In item.Attachments
‘ Criteria to save .pdf files only
If InStr(object_attachment.DisplayName, “.pdf”) Then
FileName = Replace(object_attachment.DisplayName, “.pdf”, “”)
object_attachment.SaveAsFile saveFolder & “\” & FileName & ” ” & Format(Now(), “DD-MMM-YYYY hh mm AMPM”) & “.pdf”
End If
Next
End Sub
How if the attachment is in hyperlink in outlook body email?
Hi, how would i get the script to download more than one attachment?
NOT WORKING
In Step 8 :
After clicking on ‘a script’ , Not Able to see saved VBA script in “Select a script” Option.
Plz help…!!!
Hi how to do this in excel 2007
its not working for me. DO we need to go to tool and add any reference ?
amazing stuff
When using this it keeps telling me “object required” anyone else getting that error?
Edited to save the file with the date that was sent on the file.
Public Sub SaveAutoAttach(item As Outlook.MailItem)
Dim object_attachment As Outlook.Attachment
Dim FileName As String
Dim saveFolder As String
‘ Folder location when I want to save my file
saveFolder = “D:\Data\Archive\”
For Each object_attachment In item.Attachments
‘ Criteria to save .pdf files only
If InStr(object_attachment.DisplayName, “.pdf”) Then
FileName = Replace(object_attachment.DisplayName, “.pdf”, “”)
object_attachment.SaveAsFile saveFolder & “\” & FileName & ” ” & Format(item.SentOn(), “YYYY-MM-DD hh.mm AMPM”) & “.pdf”
End If
Next
End Sub