I have the following macro that I put into my outlook 2010. The macro runs fine however, I have to manually hit alt + f11 to run it. How can I convert this to a script so it can run automatically with a rule?

THANKS!

1 Code:
  1. Option Explicit
  2.  
  3. Sub Test()
  4.  
  5.  
  6.  
  7. Dim arg1 As String
  8. Dim arg2 As String
  9. Dim arg3 As String
  10.  
  11. arg1 = "Trekker"
  12. arg2 = "XLS"
  13. arg3 = "C:\Trekker"
  14. 'If you use "" it will create a date/time stamped
  15. 'folder for you in the "My Documents" folder.
  16. 'Note: If you use this "C:\Users\Ron\test" the folder must exist
  17.  
  18. SaveEmailAttachmentsToFolder arg1, arg2, arg3
  19.  
  20.  
  21. End Sub
  22.  
  23.  
  24.  
  25. Sub SaveEmailAttachmentsToFolder(OutlookFolderInInbox As String, _
  26.                                  ExtString As String, DestFolder As String)
  27.     Dim ns As NameSpace
  28.     Dim Inbox As MAPIFolder
  29.     Dim SubFolder As MAPIFolder
  30.     Dim Item As Object
  31.     Dim Atmt As Attachment
  32.     Dim FileName As String
  33.     Dim MyDocPath As String
  34.     Dim I As Integer
  35.     Dim wsh As Object
  36.     Dim fs As Object
  37.     Dim createtime As String
  38.  
  39.     On Error GoTo ThisMacro_err
  40.  
  41.     Set ns = GetNamespace("MAPI")
  42.     Set Inbox = ns.GetDefaultFolder(olFolderInbox)
  43.     Set SubFolder = Inbox.Folders(OutlookFolderInInbox)
  44.  
  45.     I = 0
  46.     ' Check subfolder for messages and exit of none found
  47.     If SubFolder.Items.Count = 0 Then
  48.         MsgBox "There are no messages in this folder : " & OutlookFolderInInbox, _
  49.                vbInformation, "Nothing Found"
  50.         Set SubFolder = Nothing
  51.         Set Inbox = Nothing
  52.         Set ns = Nothing
  53.         Exit Sub
  54.     End If
  55.  
  56.     'Create DestFolder if DestFolder = ""
  57.     If DestFolder = "" Then
  58.         Set wsh = CreateObject("WScript.Shell")
  59.         Set fs = CreateObject("Scripting.FileSystemObject")
  60.         MyDocPath = wsh.SpecialFolders.Item("mydocuments")
  61.         DestFolder = MyDocPath & "\" & Format(Now, "dd-mmm-yyyy hh-mm-ss")
  62.         If Not fs.FolderExists(DestFolder) Then
  63.             fs.CreateFolder DestFolder
  64.         End If
  65.     End If
  66.  
  67.     If Right(DestFolder, 1) <> "\" Then
  68.         DestFolder = DestFolder & "\"
  69.     End If
  70.  
  71.     ' Check each message for attachments and extensions
  72.     For Each Item In SubFolder.Items
  73.         For Each Atmt In Item.Attachments
  74.             If LCase(Right(Atmt.FileName, Len(ExtString))) = LCase(ExtString) Then
  75.                 createtime = Format(Item.CreationTime, "d-mmm-yy") & " " & Format(Item.CreationTime, "HhNnSs AM/PM")
  76.                 FileName = DestFolder & Item.SenderName & " " & createtime & " " & Atmt.FileName
  77.                 Atmt.SaveAsFile FileName
  78.                 I = I + 1
  79.             End If
  80.         Next Atmt
  81.     Next Item
  82.  
  83.     ' Show this message when Finished
  84.     If I > 0 Then
  85.         MsgBox "You can find the files here : " _
  86.              & DestFolder, vbInformation, "Finished!"
  87.     Else
  88.         MsgBox "No attached files in your mail.", vbInformation, "Finished!"
  89.     End If
  90.  
  91.     ' Clear memory
  92. ThisMacro_exit:
  93.     Set SubFolder = Nothing
  94.     Set Inbox = Nothing
  95.     Set ns = Nothing
  96.     Set fs = Nothing
  97.     Set wsh = Nothing
  98.     Exit Sub
  99.  
  100.     ' Error information
  101. ThisMacro_err:
  102.     MsgBox "An unexpected error has occurred." _
  103.          & vbCrLf & "Please note and report the following information." _
  104.          & vbCrLf & "Macro Name: SaveEmailAttachmentsToFolder" _
  105.          & vbCrLf & "Error Number: " & Err.Number _
  106.          & vbCrLf & "Error Description: " & Err.Description _
  107.          , vbCritical, "Error!"
  108.     Resume ThisMacro_exit
  109.  
  110. End Sub