Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatically save attachment

Status
Not open for further replies.

JamesLean

Programmer
Dec 13, 2002
3,059
GB
I get a daily email that contains a single text file attachment. What I want to do is when I receive the email to automatically save that attachment to a certain location.

At the moment I have written a macro that saves the attachment and added a button to my Outlook toolbar which i just click to run it. Can anyone tell me how I would get it to run when I receive the email (much like an Outlook rule)?

The macro code is below FYI:

Code:
Sub SaveAWB()
    Dim oApp As New Outlook.Application
    Dim oItem As Object
    Dim ok As Integer
    
    On Error GoTo HandleErr
    
    Set oItem = oApp.ActiveExplorer.Selection.Item(1)

    If oItem.Attachments.Count > 0 Then
        oItem.Attachments(1).SaveAsFile "V:\Customer_Care\Clientele\Projects\AWB\awb.csv"
        
        ok = MsgBox("The file was successfully saved", , "AWB")
        Exit Sub
    Else
        ok = MsgBox("The selected email does not contain any attachments", , "AWB")
        Exit Sub
    End If
    
HandleErr:
    ok = MsgBox(Error(), , "AWB")
End Sub

--James
 
If you are using Outlook 2002, you can use the "run a script option" in the rules wizard. Otherwise, you can use the NewMail event, but, according to Sue Mosher's Outlook Programming book, this is dicey.

You may find an add-in or other suggestions at her website,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top