Solved

Save attachments and file email

Posted on 2006-10-27
6
2,741 Views
Last Modified: 2010-07-01
Hello All,

I would like to know anyone knows a function that will save the attachments of email with a specific subject ("Car Mileage Claim") to the windows directory ("C:\Car_Mileage_Attachments\"), and then move the email to an outlook folder ("Car_Mileage"). I would like this to run as the email comes in, but also when outlook opens to go through and check for any new emails.

Thanks, Dommie Lama
0
Comment
Question by:DomiLama
6 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 17818635
Hi DomiLama,

This is possible with the combination of a rule and a macro.  If using a macro is an option, then I can post the code and instructions for both.

Cheers!
0
 

Author Comment

by:DomiLama
ID: 17818736
Hi BlueDevilFan, yeah I think that might do the job. Can you send the code and I'll give it a go.

Thanks.
0
 
LVL 18

Expert Comment

by:Serena Hsi
ID: 17820101
Using VBA to Manage Your Outlook Email Attachments (tutorial and VBA walk-through)
http://www.fontstuff.com/outlook/oltut01.htm

Use the Rules wizard to trigger based on an email with an attachment, with "specific words" in the subject, perform a "custom action", and move the email to a "specified folder".
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 17827674
DomiLama,

The code for doing this is below.  Follow these instructions to use it.

1.  Start Outlook.
2.  Click Tools->Macro->Visual Basic Editor.
3.  If not already expanded, expand Modules and click on Module1.
4.  Copy the code below and paste it into the right-hand pane of the VB Editor.
5.  Edit the code as needed.  I placed comment lines where things need to change.
6.  Click the diskette icon on the toolbar to save the changes.
7.  Close the VB Editor.
8.  Click Tools->Macro->Security.
9.  Change the Security Level setting to Medium.
10.  Create a rule that runs when a new message arrives.  Set it to check the subject for the text you want to trigger on.  If found, set the rule to move the message to the "Car Mileage Claim" folder and to run the macro.  The order is immaterial.  The final rule should look something like this:

Apply this rule after the message arrives
with Car Mileage Claim in the subject
  and on this machine only
move it to the Car_Mileage folder
  and run Modules.SaveAttachmentsToDiskRule


Sub SaveAttachmentsToDiskRule(olkMessage As Outlook.MailItem)
    Dim olkAttachment As Outlook.Attachment, _
        objFSO As Object, _
        strRootFolderPath As String, _
        strFilename As String
    'Change the path on the following line to the folder you want the attachments save in
    strRootFolderPath = "C:\Car_Mileage_Attachments\"
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set olkSourceFolder = Application.ActiveExplorer.CurrentFolder
    If olkMessage.Attachments.Count > 0 Then
        For Each olkAttachment In olkMessage.Attachments
            strFilename = olkAttachment.FileName
            intCount = 0
            Do While True
                If objFSO.FileExists(strRootFolderPath & strFilename) Then
                    intCount = intCount + 1
                    strFilename = "Copy (" & intCount & ") of " & olkAttachment.FileName
                Else
                    Exit Do
                End If
            Loop
            olkAttachment.SaveAsFile strRootFolderPath & strFilename
        Next
    End If
    Set objFSO = Nothing
    Set olkAttachment = Nothing
    Set olkMessage = Nothing
End Sub
0
 
LVL 1

Expert Comment

by:penlandt
ID: 24583120
I can't understand why - but this solution is not working for me.  I've tried.  The macro moves the message to the folder it should, but it does not save the attachments.  I tried putting a break point in the code so that I could step through it but it appears that macro never runs because the break point is never reached.  Any idea why?

Here's my rule:

Apply this rule after the message arrives
with New eBay Listing in the subject
  and on this machine only
move it to the Completed Messages folder
  and run Project1.SaveAttachmentsToDiskRule
  and mark it as read
Sub SaveAttachmentsToDiskRule(olkMessage As Outlook.MailItem)
    Dim olkAttachment As Outlook.Attachment, _
        objFSO As Object, _
        strRootFolderPath As String, _
        strFilename As String
    'Change the path on the following line to the folder you want the attachments save in
    strRootFolderPath = "C:\eBayListings\"
    Stop
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set olkSourceFolder = Application.ActiveExplorer.CurrentFolder
    If olkMessage.Attachments.Count > 0 Then
        For Each olkAttachment In olkMessage.Attachments
            strFilename = olkAttachment.FileName
            intCount = 0
            Do While True
                If objFSO.FileExists(strRootFolderPath & strFilename) Then
                    intCount = intCount + 1
                    strFilename = "Copy (" & intCount & ") of " & olkAttachment.FileName
                Else
                    Exit Do
                End If
            Loop
            olkAttachment.SaveAsFile strRootFolderPath & strFilename
        Next
    End If
    Set objFSO = Nothing
    Set olkAttachment = Nothing
    Set olkMessage = Nothing
End Sub

Open in new window

0
 
LVL 1

Expert Comment

by:penlandt
ID: 24583666
Please disregard my previous post - I had forgotten to save the Project - that's why it wasn't working.  Rookie mistake ;-)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
Many people use more than one email account and so it becomes difficult for them to manage them when they use separate accounts,  so, in this article, I have shared an easy way to add Other Mail Accounts in your Google Inbox. It helps to combine all…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question