• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Save an Attachment as Current File Type

PipBoy808

Member
Hi,

I have some code that runs on a schedule to look through an outlook account, find attachments and save them.

The files are .xls files, and the macro saves them as "YYMMDD.xls" depending on the day they are sent.

Strangely, the files it has been downloading of late are corrupted as the file extension does not match the original file type. This implies that I'm saving them down as the wrong file type, but they are definitely .xls files.

Rather than hard-coding '.xls' into the filename in the code, is there a method I can use to save files as the file type they are sent in regardless of what it is, therefore making it dynamic? Something like 'FileName.CurrentFileType' ? This would help me in trying to find out why these files are apparently being corrupted
 
You were pretty close with your guess. :)
Code:
Sub KeepFormat()
Dim fPath As String
'What folder?
fPath = "C:\My Documents\"
ThisWorkbook.SaveAs Filename:=fPath & Format(Date, "YYMMDD"), FileFormat:=ThisWorkbook.FileFormat
End Sub
 
Back
Top