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
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