I initially had this code running to save attachments from emails that come in. My code would loop through the entire folder and for any attachments that were there, it would save the attachment and remove it from the email. I had a rule in place to make the macro fire whenever the mail I wanted came in. However the attachment would never save down when the mail came. There were no errors, and debugging manually worked just fine. In addition, running the rule immediately afterwards by clicking the 'Run rules now' button would work just fine too. So after trying out a million different ways to save the attachments, I started getting really annoyed and set up a test to see what the hell outlook was doing. So here is the problem.
This is the outlook rule I have set up:
Apply this rule after the message arrives from xxxxx move it to the Macrotest folder and run Project1.ThisOutlookSession.sayhi
I discovered though that what outlook does is fire the script Before it transfers the mail into the folder my macro looks in. Hence, it never finds the new file. Obviously then when its done the mail comes into the folder so when I run it manually it works just fine. So how can I fix the order that this rule comes in?
Public Sub sayhi(item As Outlook.MailItem)
Dim objNS As Outlook.NameSpace
Dim olfolder As Outlook.MAPIFolder
Dim msg As Outlook.MailItem
Set objNS = Application.GetNamespace("MAPI")
Set olfolder = objNS.GetDefaultFolder(olFolderInbox)
Set olsubfolder = olfolder.Folders("Macrotest")
Set oapp = CreateObject("Shell.Application")
For Each myitem In olsubfolder.Items
MsgBox "hellothere"
myitem.UnRead = False
Next
End Sub