Hi all,
Can I make a rule or code to save or forward automatically an specific file to a desired target location when email arrives.
Target Location is:
F:\Business Optimization Sales Analysis\DSR Link File
Hi all,
Can I make a rule or code to save or forward automatically an specific file to a desired target location when email arrives.
Target Location is:
F:\Business Optimization Sales Analysis\DSR Link File
T-ogether
E-veryone
A-chieves
M-ore
One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.
First you need to add this code to the "ThisOutlookSession" module in the Outlook VBE window:
[vba]
Sub SaveAttachmentRule(Item As Outlook.MailItem)
Dim att As Attachment
Dim strPath As String
strPath = "F:\Business Optimization Sales Analysis\DSR Link File\"
For Each att In Item.Attachments
' change the name of the attached file you are looking for
If att.FileName = "Name of attachment file.txt" Then
att.SaveAsFile strPath & att.FileName
End If
Next att
End Sub
[/vba]
I'm assuming that you're looking for a specific attachment, so change "Name of attachment file.txt" to the name of the attached file you are expecting to receive.
When you setup your rule, you need to check incoming mail. If the mail message has a consistent subject, you can specific the subject to look for, otherwise you may have to look at every message with an attachment.
The action to perform is "run a script", and you should be able to select "Project1.ThisOutlookSession.SaveAttachmentRule" as the script to run.
What about if there is a file on that folder having the same file name. How can I replace the existing file to the latest file I have recieved?
T-ogether
E-veryone
A-chieves
M-ore
One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.
This what I did so far. I don't know if I did it right. please check over it.
[vba]
Sub SaveAttachmentRule(Item As Outlook.MailItem)
Dim att As Attachment
Dim strPath As String
strPath = "F:\Business Optimization Sales Analysis\DSR Link File\"
For Each att In Item.Attachments
If att.FileName = "SALES-2007-05.xls" And "Home Delivery Sales 2007.xls" And "4.SALES MAY-2007.xls" Then
att.SaveAsFile strPath & att.FileName
End If
Next att
End Sub
Private Sub Application_NewMail()
Project1.ThisOutlookSession.SaveAttachmentRule ' Compile Error: Argument Not Optional
End Sub
[/vba]
T-ogether
E-veryone
A-chieves
M-ore
One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.
[VBA]
Sub SaveAttachmentRule(Item As Outlook.MailItem)
Dim att As Attachment
Dim strPath As String
strPath = "F:\Business Optimization Sales Analysis\DSR Link File\"
' loop through each attachment
For Each att In Item.Attachments
Select Case att.FileName
Case "SALES-2007-05.xls", "Home Delivery Sales 2007.xls", _
"4.SALES MAY-2007.xls"
att.SaveAsFile strPath & att.FileName
End Select
Next att
End Sub
[/VBA]
To setup the rule, in Outlook, select Tools | Rules and Alerts | New Rule | Start from a blank rule. In Step 1, select "Check messages when they arrive", then Next. Tick the condition "which has an attachment", then Next. Tick the action "run a script".
In the "Step 2" box, click on "a script" (which is underlined) and select "Project1.ThisOutlookSession.SaveAttachmentRule". Click Next twice, give your rule a name, then click Finish.
Well I can adjust my time schedule right now. Instead of 8am, I guess I'll be moving it to 10am ... geekgirlau you have just made my life easier. Thanks the code works well...
Originally Posted by geekgirlau
T-ogether
E-veryone
A-chieves
M-ore
One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.