wallen1605
Member
- Outlook version
- Outlook 2013 32 bit
- Email Account
- Exchange Server 2013
Hi All
I am new to the forum and need help please with a piece of code which will achieve what the title says above.
I currently have the below code in a module called by an outlook rule to run on incoming emails. All incoming attachments are .xlsx attachments and are renamed with the same file extension. The issue I have is that once the vb code renames the file name to the current date and time and saves the file in the network folder, I can no longer open the file and receive the error that the file format or extension may not be correct or the file is corrupt, but the file is fine before renaming.
Also the code below causes confusion on emails which have more than 1 attachment, so ideally I need the code to work through all attachments in the incoming email.
Code as follows: (Many thanks in advance for your help):
I am new to the forum and need help please with a piece of code which will achieve what the title says above.
I currently have the below code in a module called by an outlook rule to run on incoming emails. All incoming attachments are .xlsx attachments and are renamed with the same file extension. The issue I have is that once the vb code renames the file name to the current date and time and saves the file in the network folder, I can no longer open the file and receive the error that the file format or extension may not be correct or the file is corrupt, but the file is fine before renaming.
Also the code below causes confusion on emails which have more than 1 attachment, so ideally I need the code to work through all attachments in the incoming email.
Code as follows: (Many thanks in advance for your help):
Code:
Sub SaveAttachmentsToDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
Dim att As Object
saveFolder = "\\server\share" ' change to your path
For Each objAtt In itm.Attachments
If itm.Attachments.Count > 0 Then
For Each att In itm.Attachments
If att.FileName Like "*.xlsx" Then
objAtt.SaveAsFile saveFolder & "\" & Format(Now, "dd-mm-yy-hh-mm-ss") & ".xlsx"
itm.UnRead = False
End If
Next att
End If
Next
End Sub