Outlook email attachment downloading VBA not working as required

JohnTeee

New Member
Joined
Feb 19, 2016
Messages
1
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?

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
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Forum statistics

Threads
1,225,761
Messages
6,186,882
Members
453,381
Latest member
CGDobyns

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top