Trouble with VBA to save email attachment

NatetheGreat

Active Member
Joined
Nov 18, 2013
Messages
268
Hi All,

I expect this may need to go into the "Other Languages" part of the forum, but I'm not entirely certain.

I have the following code within my Outlook VBE

Code:
Sub saveattachtodiskspots(itm As Outlook.MailItem)
Dim objatt As Outlook.Attachment
Dim savefolder As String
Dim dateformat
Dim extrabite As String
Dim extrabite2 As String
dateformat = Format(Now, "mmdd H-mm")
savefolder = "C:\Users\USER\Desktop\Daily Reports\spots\"
extrabite = itm.subject
extrabite2 = Replace(extrabite, "/", "_")
For Each objatt In itm.Attachments
objatt.SaveAsFile savefolder & extrabite2 & ".xls"
 Set objatt = Nothing
 Next
 
 
End Sub

The code is supposed to save the attached spreadsheet into my local disk, naming the file as the subject of the email, but replacing the "/" with "_" so as to be a valid file name for windows. This works in other areas, but for some reason at the moment it is saving the file simply as "FW" and not as xls but as a notepad?

Anyone see something wrong with my code ?
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Forum statistics

Threads
1,225,681
Messages
6,186,411
Members
453,352
Latest member
OrionF

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