wallen1605
Board Regular
- Joined
- Dec 15, 2017
- Messages
- 57
Hi Guys
I know technically this is a question for Outlook, however the issue is with the Excel file I am trying to open.
Basically, I have a rule in outlook that checks incoming emails for an attachment and if found, it renames and saves the attachment to a network folder with todays date and time. All the attachments are successfully renaming and saving, however, when I open each of the files, I receive an error stating the file is either corrupt or the file extension is not valid. I have tested the incoming files before renaming and they open fine, it is only when the code renames them that I cannot open them?
My code example is below, please could someone help me out as I have exhausted the web for the correct answer and cannot find it.
EDIT: Backslash is in my code but not showing in the following line when I post to the forum between the "".
I know technically this is a question for Outlook, however the issue is with the Excel file I am trying to open.
Basically, I have a rule in outlook that checks incoming emails for an attachment and if found, it renames and saves the attachment to a network folder with todays date and time. All the attachments are successfully renaming and saving, however, when I open each of the files, I receive an error stating the file is either corrupt or the file extension is not valid. I have tested the incoming files before renaming and they open fine, it is only when the code renames them that I cannot open them?
My code example is below, please could someone help me out as I have exhausted the web for the correct answer and cannot find it.
Code:
Sub SaveAttachmentsToDisk(itm As Outlook.MailItem)Dim objAtt As Outlook.Attachment
Dim saveFolder As String
Dim att As Object
saveFolder = [URL="file://\\server\share"]\\server\share[/URL] ' 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
EDIT: Backslash is in my code but not showing in the following line when I post to the forum between the "".
Code:
objAtt.SaveAsFile saveFolder & "" & Format(Now, "dd-mm-yy-hh-mm-ss") & ".xlsx"
Last edited: