VBA Excel/Outlook - Auto save attachment

natheplas

Board Regular
Joined
Aug 28, 2016
Messages
97
Hi All,

The premise I'm struggling with is to save excel attachments to folders on my PC automatically, but using a rule that looks for specific words in attachments, saves them to different folder locations.

For example test in subject, in email 1, would send it to folder1. Then test2 in subject, in email 2, would send it to folder2.

I've found a useful VBA online and changed it slightly to work with my data, it works perfectly, but I can only get it to work for 1 subject/folder.

I need 3 different subject words in the email, starting a rule to run a script, to send each attachment t different folders.

The moment I add a second module in VBA I can't see any of the scripts.

Or if I add another script, below the first one, but change the file directory it stops working.

Please see the VBA below and can someone tell me what I am doing wrong?!

Thanks in advance for any help offered.


Sub saveAttachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
saveFolder = "MY FOLDER LOCATION"
For Each objAtt In itm.Attachments
objAtt.SaveAsFile saveFolder & "" & objAtt.DisplayName
Set objAtt = Nothing
Next
End Sub
 
Last edited:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hi All,

Figured out where I was going wrong! I had the same script name for each script.....Captain Obvious!
 
Upvote 0

Forum statistics

Threads
1,215,001
Messages
6,122,648
Members
449,092
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top