Guest User

Untitled

a guest
Mar 21st, 2018
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. Sub RunRulesSecondary()
  2.  
  3. Dim oStores As Outlook.Stores
  4. Dim oStore As Outlook.Store
  5.  
  6. Dim olRules As Outlook.Rules
  7. Dim myRule As Outlook.Rule
  8. Dim olRuleNames() As Variant
  9. Dim name As Variant
  10.  
  11. ' Enter the names of the rules you want to run
  12. olRuleNames = Array("Rule1")
  13.  
  14. Set oStores = Application.Session.Stores
  15. For Each oStore In oStores
  16. On Error Resume Next
  17.  
  18. ' use the display name as it appears in the navigation pane
  19. If oStore.DisplayName <> "email@domain.ddns.net" Then
  20.  
  21. Set olRules = oStore.GetRules()
  22.  
  23. For Each name In olRuleNames()
  24.  
  25. For Each myRule In olRules
  26. Debug.Print "myrule " & myRule
  27.  
  28. If myRule.name = name Then
  29.  
  30. ' inbox belonging to oStore
  31. ' need GetfolderPath functionhttp://slipstick.me/4eb2l
  32. myRule.Execute ShowProgress:=True, Folder:=GetFolderPath(oStore.DisplayName & "Inbox")
  33.  
  34. ' current folder
  35. ' myRule.Execute ShowProgress:=True, Folder:=Application.ActiveExplorer.CurrentFolder
  36.  
  37. End If
  38. Next
  39. Next
  40.  
  41. End If
  42. Next
  43. End Sub
  44.  
  45. Function GetFolderPath(ByVal FolderPath As String) As Outlook.Folder
  46. Dim oFolder As Outlook.Folder
  47. Dim FoldersArray As Variant
  48. Dim i As Integer
  49.  
  50. On Error GoTo GetFolderPath_Error
  51. If Left(FolderPath, 2) = "\" Then
  52. FolderPath = Right(FolderPath, Len(FolderPath) - 2)
  53. End If
  54. 'Convert folderpath to array
  55. FoldersArray = Split(FolderPath, "")
  56. Set oFolder = Application.Session.Folders.Item(FoldersArray(0))
  57. If Not oFolder Is Nothing Then
  58. For i = 1 To UBound(FoldersArray, 1)
  59. Dim SubFolders As Outlook.Folders
  60. Set SubFolders = oFolder.Folders
  61. Set oFolder = SubFolders.Item(FoldersArray(i))
  62. If oFolder Is Nothing Then
  63. Set GetFolderPath = Nothing
  64. End If
  65. Next
  66. End If
  67. 'Return the oFolder
  68. Set GetFolderPath = oFolder
  69. Exit Function
  70.  
  71. GetFolderPath_Error:
  72. Set GetFolderPath = Nothing
  73. Exit Function
  74. End Function
Add Comment
Please, Sign In to add comment