Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-18-2015, 04:13 AM
AndyDDUK AndyDDUK is offline VBA rule to fire off in specified folder only Windows 7 64bit VBA rule to fire off in specified folder only Office 2010 64bit
Advanced Beginner
VBA rule to fire off in specified folder only
 
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
  #2  
Old 11-17-2015, 02:55 PM
niton niton is offline VBA rule to fire off in specified folder only Windows 7 64bit VBA rule to fire off in specified folder only Office 2010 64bit
Competent Performer
 
Join Date: Jul 2012
Posts: 102
niton is on a distinguished road
Default

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
Reply With Quote
  #3  
Old 11-17-2015, 10:05 PM
gmayor's Avatar
gmayor gmayor is offline VBA rule to fire off in specified folder only Windows 7 64bit VBA rule to fire off in specified folder only Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA rule to fire off in specified folder only Outlook VBA rule to search email attachements and move the emails into a folder genius7 Outlook 6 09-09-2014 07:01 AM
VBA rule to fire off in specified folder only Can't select specified folder when creating rule Eebygum Outlook 3 06-17-2013 06:10 AM
VBA rule to fire off in specified folder only Fire drop down Macro on change carlosriver24 Word 1 08-02-2012 07:18 PM
VBA rule to fire off in specified folder only Rule to move sent messages to a specific folder LouisOscar Outlook 1 08-17-2011 05:42 AM
VBA rule to fire off in specified folder only Rule will not save on Publc Folder doppers Outlook 2 07-18-2011 05:27 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:44 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft