Download attachments rule

Jan 26, 2010
Reaction score
I'm trying to design a macro that I will be able to run via rule when an email arrives.

So I'll give the whole details of what I want to do and how I think I would do it...

1. By creating a rule I want to make it so a subject is checked, and if it displays "Corr Test Result" I want it to move to a folder located is Correspondent.pst sub folder "Corr Test Results." This is all basic rule stuff that I can create with the wizard.

2. Then I want the rule to run a script where it will save the attachement on that email to a folder on my HD.

One thing to consider, the name of the attachment each time is going to be the same, test.xml. I dont care about the name and it can be renamed to anything, but I cant have it over-write when saving.

If anyone could help me out here that would be great. Thank you!
Jan 26, 2010
Reaction score
Maybe a better way to ask... is how could I get this code to show up in the script drop-down in the rules....

Sub Corr_Attachment_Saver()

Dim ns As NameSpace

Dim Item As Object

Dim Atmt As Attachment

Dim FileName As String

Dim i As Integer

Set ns = GetNamespace("Mapi")

Set Inbox = ns.GetDefaultFolder(olFolderInbox)

Set SubFolder = Inbox.Folders("Incoming Corr Test Results")

i = 0

For Each Item In SubFolder.Items

For Each Atmt In Item.Attachments

If Right(Atmt.FileName, 3) = "xml" Then

FileName = "C:\Documents and Settings\fochrist\Desktop\Corr Test Results\" & Item.EntryID & Atmt.FileName

Atmt.SaveAsFile FileName

i = i + 1

End If

Next Atmt

Next Item


Set Atmt = Nothing

Set Item = Nothing

Set ns = Nothing

Exit Sub

End Sub

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question