this is a sample section of code for running in outlook as a custom rule, which runs a script depending on what version of outlook you have, you will need to change the fred.txt bit accordingly and setup the rule, this code needs to be pasted as a module in ThisOutlookSession
'****
' Routine for a custom rule for incoming emails
' Assembled from various Internet resources, and trial and error
'
' Author Jim Ward
' Creation November 2007
'
'
'****
' Firstly give the routine a name it matters not the name what is important is defining
' the passed parameter as type MAILITEM. You can then create a rule and use the Run A Script
' option and the name of the routine is displayed. Without the parameter it will not be seen !!
'****
Sub IncomingCheck(IncomingMail As MailItem)
Dim strID As String
Dim olNS As Outlook.NameSpace
Dim olMail As Outlook.MailItem
Dim oParentFolder As Outlook.MAPIFolder
'****
' What is key about this method is that by grabbing the ID and processing it from there it
' circumvents any OUTLOOK intervention asking to be granted access to the ITEM for security
' purposes
'****
strID = IncomingMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set olMail = olNS.GetItemFromID(strID)
If InStr(1, olMail.Subject, "Productivity Report", vbTextCompare) > 0 Then
Set myattach = olMail.Attachments
'****
' get the desktop location
'****
Set oWSS = CreateObject("WScript.Shell")
szDesktopPath = oWSS.SpecialFolders(szlocation)
myattach(1).SaveAsFile szDesktopPath & "fred.txt"
End If
'****
' Clear out memory, all done
'****
Set olMail = Nothing
Set olNS = Nothing
End Sub