Hi all, I have the following code running triggered by a rule for certain emails with excel attachments arriving to my inbox. This code gets around no autoforwarding emails as set by the server as well as downloading the excel attachment and storing it on a network folder.
The issue I have been having is sometimes the code will not download the excel file or it will duplicate the file. It does take some time to save to the network drive (up to 20 seconds) as it takes some time to connect over a VPN.
Can anyone explain this issue and potentially a workaround for it?
The issue I have been having is sometimes the code will not download the excel file or it will duplicate the file. It does take some time to save to the network drive (up to 20 seconds) as it takes some time to connect over a VPN.
Can anyone explain this issue and potentially a workaround for it?
Code:
Sub AutoForwardAndSave(Item As Outlook.MailItem)
Dim myFwd As Outlook.MailItem
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
Dim dateFormat
Set myFwd = Item.Forward
myFwd.Recipients.Add "email@domain.com"
myFwd.Send
Set myFwd = Nothing
dateFormat = Format(Now, "yyyy-mm-dd HH-mm")
saveFolder = "\\networkdrive\shared folder"
For Each objAtt In Item.Attachments
If InStr(objAtt.DisplayName, ".xls") Then
objAtt.SaveAsFile saveFolder & "\" & dateFormat & " " & Item.Subject & ".xls"
End If
Set objAtt = Nothing
Next
End Sub