PDA

View Full Version : [SOLVED:] With used macro the saved date is incorrect, how can I make sure this is correct?



WillemKanon
04-28-2017, 12:17 AM
Hi,

I use the macro below to save a selection of e-mail attachements. (thanks to gmayor)


Option Explicit
Public Sub saveAttachToDisk()

Dim objAtt As Outlook.Attachment
Dim olMsg As Outlook.MailItem
Dim strDate As String
Dim strName As String
Dim lngAns As Long
Dim oFrm As UserForm1
Const saveFolder1 As String = "C:\Temp\Test1\"
Const saveFolder2 As String = "C:\Temp\Test2\"
Const saveFolder3 As String = "C:\Temp\Test3\"


On Error Resume Next
Set olMsg = ActiveExplorer.Selection.Item(1)
strDate = Format(Now, " yyyy-mm-dd")
For Each objAtt In olMsg.Attachments
Set oFrm = New UserForm1
With oFrm
.Caption = "Select Save Option"
.CommandButton1.Caption = "Doorgaan"
.CommandButton2.Caption = "Opslaan afbreken"
.TextBox1.Text = objAtt.FileName
.OptionButton1.Caption = "Opslaan in Verkooporders"
.OptionButton2.Caption = "Customer 1"
.OptionButton3.Caption = "Customer 1"
.OptionButton4.Caption = "Niet opslaan"
.OptionButton4.Value = True
.Show
If .Tag = 0 Then GoTo lbl_Exit
strName = oFrm.TextBox1.Text
Select Case True
Case Is = .OptionButton1.Value
objAtt.SaveAsFile saveFolder1 & strName
Case Is = .OptionButton2.Value
objAtt.SaveAsFile saveFolder2 & strName
Case Is = .OptionButton3.Value
objAtt.SaveAsFile saveFolder3 & strName
Case Else
End Select
End With
Unload oFrm
Next objAtt
lbl_Exit:
Set oFrm = Nothing
Set objAtt = Nothing
Set olMsg = Nothing
Exit Sub
End Sub


The code works perfectly, but the saved date (see picture below) is the date and time the e-mail was send instead of the date and time the file was saved.
Is it possible to use the date and time of the moment of saving instead of the moment the e-mail was send?

19042
Thanks

Grtz WillemKanon

gmayor
04-28-2017, 05:53 AM
The code you have listed includes a variable strDate which is the date now

strDate = Format(Now, " yyyy-mm-dd")
This isn't used in the macro, but can be added to the filename e.g.

strName = strDate & Chr(32) & oFrm.TextBox1.Text
If you save an attachment, the filedate should be the sate it was saved.

e.g. I saved the following attachment a few minutes ago:

19043

WillemKanon
04-28-2017, 06:20 AM
I changed the code to use the strDate
and tried to save another document to see what the date is
19045

as you can see it is still the time at which the mail was send.
maybe you tried the code with an e-mail that was just send?

WillemKanon
05-03-2017, 12:51 AM
Hi,

I read on another forum that SetFileDateTime could be the solution to the problem.
Unfortunately, I cannot build this into my code myself because I'm not that good at writing code.

Is there anyone who could try this for me?

Thanks

WillemKanon
05-05-2017, 04:26 AM
>>The question is solved on another forum<<