PDA

View Full Version : Don't want the date changed



certem
01-15-2012, 07:45 AM
I use the code below to save the attachments but the date of the attachments become today's date. I want them to stay their original date.

Thank you for your helps.


Public Sub saveAttachtoDisk()
Dim objOL As Outlook.Application
Dim itm As Outlook.MailItem
Dim objAtt As Outlook.Attachments
Dim objSelection As Outlook.Selection
Dim i As Long
Dim lngCount As Long
Dim saveFolder As String
Dim adet As Long

saveFolder = "C:\Users\Ahmet\Desktop\GEÇİCİ\"
Set objOL = CreateObject("Outlook.Application")
Set objSelection = objOL.ActiveExplorer.Selection
adet = 0
For Each itm In objSelection
adet = adet + 1
Set objAtt = itm.Attachments

lngCount = objAtt.Count

For i = lngCount To 1 Step -1

objAtt.Item(i).SaveAsFile saveFolder & adet & objAtt.Item(i).FileName
Next i

Next

MsgBox adet
Set objOL = Nothing
Set objSelection = Nothing
Set objAtt = Nothing
Set itm = Nothing

End Sub

JP2112
01-23-2012, 01:02 PM
When you save an attachment, today's date is the date of the attachment because as far the file system is concerned, that is the date the file first appeared. It has no way to tell the "date of the attachment."

I have some code here that lets you check when a file was last modified. You can use it to try and modify that value, but I don't know if that is possible.

http://www.jpsoftwaretech.com/vba/using-wmi-services-in-vba/check-file-properties-using-wmi/