#1
|
|||
|
|||
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 |
#2
|
|||
|
|||
Code:
Private Sub attSelect() Dim oItm As Object For Each oItm In ActiveExplorer.Selection If TypeOf oItm Is mailItem Then saveAttachtoDisk2 oItm End If Next End Sub |
#3
|
||||
|
||||
While Niton's suggestion will work, it will take no account of duplicate file names. For the additional code see https://www.msofficeforums.com/outlo...ts-folder.html
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Outlook VBA rule to search email attachements and move the emails into a folder | genius7 | Outlook | 6 | 09-09-2014 07:01 AM |
Can't select specified folder when creating rule | Eebygum | Outlook | 3 | 06-17-2013 06:10 AM |
Fire drop down Macro on change | carlosriver24 | Word | 1 | 08-02-2012 07:18 PM |
Rule to move sent messages to a specific folder | LouisOscar | Outlook | 1 | 08-17-2011 05:42 AM |
Rule will not save on Publc Folder | doppers | Outlook | 2 | 07-18-2011 05:27 AM |