user3088476
user3088476

Reputation: 155

Saving email attachments automatically with a specific subject title

Hope someone can shed some light on to this for me.

I have written a script which should save an email attachment with a specific heading (I have this part specified in the rules section of outlook, or should it be written into the script?)

For some reason it isn't working. Below is the script I have: -

Public Sub saveAttachmentTtoDisk(itm As Outlook.MailItem)

Dim objAtt As Outlook.Attachment

Dim saveFolder As String
saveFolder = "C:/LocationOfFolderToSaveTo"
For Each objAtt In itm.Attachments
    objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
    Set objAtt = Nothing
Next
End Sub

Can anyone see where I have gone wrong.

Upvotes: 1

Views: 6514

Answers (1)

0m3r
0m3r

Reputation: 12499

saveFolder = "C:/LocationOfFolderToSaveTo"

Should be saveFolder = "C:\LocationOfFolderToSaveTo\"


To specify by subject line - try adding IF function to check if the specified condition is being met or not

If olItem.Subject = "Subject line here" Then

Option Explicit
Public Sub Save_Attachment(olItem As Outlook.MailItem)
    Dim olAttch As Outlook.Attachment
    Dim sPath As String

    'sPath = Environ("USERPROFILE") & "\Documents\"
    sPath = "C:\Temp\"

    For Each olAttch In olItem.Attachments
        If olItem.Subject = "0m3r" Then
            olAttch.SaveAsFile sPath & "\" & olAttch.DisplayName
        End If
    Next

    Set olAttch = Nothing
End Sub

Upvotes: 1

Related Questions