• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Autosave Attachment and Rename

dyasmonroe

New Member
Outlook version
Outlook 2013 64 bit
Email Account
Outlook.com (as MS Exchange)
#1
I have the following code that autosaves the attachments from any incoming mail and renames the attachment with the date and time so as not to overwrite.

Code:
Public Sub AutoSaveAttachment(itm As Outlook.MailItem)

Dim objAtt As Outlook.Attachment
Dim saveFolder As String
Dim dateFormat
    saveFolder = "C:\temp"
    dateFormat = Format(Now, "mm.dd.yyyy (Hh.Nn)")
        For Each objAtt In itm.Attachments
            If InStr(objAtt.DisplayName, ".pdf") Then
            objAtt.SaveAsFile saveFolder & "\" & "Attch " & dateFormat & "." & "pdf"
        End If
      Set objAtt = Nothing
    Next
End Sub
I want to add the senders name before the date/time so I tried this which doesn't work. Run-time error.

Code:
'Sub AttachmentDownloader(itm As Outlook.MailItem)

'Dim objAtt As Outlook.Attachment
'Dim saveFolder As String
'Dim sndrName As String
'Dim dateFormat
   ' dateFormat = Format(Now, "mmddyyyy_(Hh.Nn)")
    'sndrName = objAtt.SenderName & "_"
    'saveFolder = "C:\temp"
    
     'For Each objAtt In itm.Attachments
           ' If InStr(objAtt.DisplayName, ".pdf") _
           ' Or InStr(objAtt.DisplayName, ".xlsx") _
           ' Or InStr(objAtt.DisplayName, ".xlsm") _
           ' Or InStr(objAtt.DisplayName, ".doc") _
          '  Or InStr(objAtt.DisplayName, ".docx") Then
         objAtt.SaveAsFile saveFolder & "\" & "sndrName" & dateFormat & objAtt.DisplayName
          
    'End If         
       'Set objAtt = Nothing
    'Next
'End Sub
Where am I going wrong?
 

niton

New Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server 2010
#2
objAtt does not have a SenderName property. Use itm instead.
 

Similar threads