View Single Post
 
Old 09-18-2015, 04:13 AM
AndyDDUK AndyDDUK is offline Windows 7 64bit Office 2010 64bit
Advanced Beginner
 
Join Date: Oct 2012
Posts: 32
AndyDDUK is on a distinguished road
Default VBA rule to fire off in specified folder only

Hi there

I want to download attachments in highlighted emails or a folder..

I've found the following code which runs the rules, one of which runs a script to download files

Do you know how to modify:

1) "Run_Rules" so it to only runs one specified rule in all emails which have been moved to a specific folder? or
2) To change the script so it only downloads attachments in emails I have selected, or which have been moved to a specific folder?


Sub Run_Rules()
Dim st As Outlook.Store
Dim myRules As Outlook.Rules
Dim rl As Outlook.Rule
Dim count As Integer
Dim ruleList As String
'On Error Resume Next

' get default store (where rules live)
Set st = Application.Session.DefaultStore
' get rules
Set myRules = st.GetRules

' iterate all the rules
For Each rl In myRules
' determine if it's an Inbox rule
If rl.RuleType = olRuleReceive Then
' if so, run it
rl.Execute
count = count + 1
End If
Next

Set rl = Nothing
Set st = Nothing
Set myRules = Nothing
End Sub


Script:
Public Sub saveAttachtoDisk2(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String


saveFolder = "C:\OutlookTest"
For Each objAtt In itm.Attachments
objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
Set objAtt = Nothing
Next
End Sub


Many thanks

Andy
Reply With Quote