NessPJ
Active Member
- Joined
- May 10, 2011
- Messages
- 422
- Office Version
- 365
Hi,
I tried to make/search a code that could help me quickly save an attachment to a fixed folder that also adds the 2 digits of the month to the filename.
When i run the routine shown below nothing is happening. Am i doing something wrong?
I tried to make/search a code that could help me quickly save an attachment to a fixed folder that also adds the 2 digits of the month to the filename.
When i run the routine shown below nothing is happening. Am i doing something wrong?
VBA Code:
Sub SaveAttachmentWithDate()
Dim date_now As Date
Dim dateStamp As String
Dim LRandomNumber As Integer
For i = lngCount To 1 Step -1
'Set the Folder to save the Attachment:
strFolderpath = "C:\Temp\Attachments\"
' Get the file name.
strFile = objAttachments.Item(i).FileName
'LRandomNumber = Int((300 - 200 + 1) * Rnd + 200) Not used for now
date_obj = objMsg.ReceivedTime ' Now()
dateStamp = Format(date_obj, "mm")
' Combine with the path to the folder.
strFile = strFolderpath & strFile & dateStamp
' Save the attachment as a file.
objAttachments.Item(i).SaveAsFile strFile
Next i
End Sub