I need to use rule for some specific mails I'm recieving. I have to save attachment to specific folder I.E. D:\TEST) then move message to specific subfolder in ANOTHER FILE mailbox file attached to Outlook.
I found and adapt code for my needs but outlook rules are "numb" and there is no possibility to change order of rules step execute:
If msg hit rule:
Move MSG to specific folder
Then Run script
So in conclusion a script didn't find a MSG because it's moved by rule (I can't find an option to reverse order and get:
If msg hit rule:
Run script
Then Move MSG to specific folder So solution is to write a script and attach when rule is triggered.
Public Sub SaveAttach(Item As Outlook.MailItem)
If Item.Attachments.Count > 0 Then
Dim objAttachments As Outlook.Attachments
Dim lngCount As Long
Dim strFile As String
Dim sFileType As String
Dim strFolderpath As String
Dim i As Long
Dim myDestFolder As Outlook.Folder
Set myDestFolder = myInbox.Folders("Mails").Folders("Exported")
Set objAttachments = Item.Attachments
lngCount = objAttachments.Count
For i = lngCount To 1 Step -1
strFile = objAttachments.Item(i).FileName
strFolderpath = "D:\TEMP\"
strFile = strFolderpath & strFile
objAttachments.Item(i).SaveAsFile strFile
Next i
Item.Move myDestFolder
End If
End Sub
Above code putted to ThisOutlookSession and then connected to rule "run script" works, but how to expand this code above to move MSG who attachment I extracted to another outlook subfolder in I.E. Mails\Exported\ ?
edit:
Added lines
Dim myDestFolder As Outlook.Folder
Set myDestFolder = myInbox.Folders("Mails").Folders("Exported")
Item.Move myDestFolder
But still something is wrong and VBA at this mode (run script as part of rule) dont run debug and cant see error message, it's just not work (i can only set msgbox "Im here" to track what part of script wont work :/
A tree of files looks like this
1 Inbox(DefaultIncomingMailsFile.ost (IMAP))
2 Mails(LocalFile.pst)
2a Exported (subfolder in Mails where should be moved mails after attachment extraction)
SaveAttach ActiveInspector.CurrentItem
. Details here stackoverflow.com/questions/11870717/…. – niton