I am using the following code to save attachments based using subject line as the file name...
Public Sub KronosPics()
Dim objOL As Outlook.Application
Dim objMsg As Outlook.MailItem
Dim objAttachments As Outlook.Attachments
Dim objSelection As Outlook.Selection
Dim i As Long
Dim lngCount As Long
Dim strFile As String
Dim strFolderpath As String
Dim strDeletedFiles As String
Dim strDateFileName As String
Dim strFileExtension As String
Dim strFileName As String
Dim objSubject As String
Dim strSubject As String
Dim emailsub As String
Dim dtDate As Date
Dim dName As String
strFolderpath = "S:\Departments\Service & Production\Public\Kronos Service Pictures"
On Error Resume Next
Set objOL = CreateObject("Outlook.Application")
Set objSelection = objOL.ActiveExplorer.Selection
strFolderpath = strFolderpath & "\2015 RTV\"
For Each objMsg In objSelection
Set objAttachments = objMsg.Attachments
lngCount = objAttachments.Count
If lngCount > 0 Then
dtDate = objMsg.SentOn
dName = Format(dtDate, "mm.dd.yyyy", vbUseSystemDayOfWeek, vbUseSystem)
For i = lngCount To 1 Step -1
If objAttachments.Item(i).Size > 10000 Then
emailsub = ActiveExplorer.Selection.Item(1).Subject
sName = Left$(emailsub, 10)
strFileExtension = ".jpeg"
strFile = strFolderpath & sName & " - " & dName & strFileExtension
objAttachments.Item(i).SaveAsFile strFile
End If
Next i
End If
Next
ExitSub:
Set objAttachments = Nothing
Set objMsg = Nothing
Set objSelection = Nothing
Set objOL = Nothing
End Sub
The code work great but I do not know what to do if there are multiple attachments on the email. So how do I modify this code so that the file name includes something like Pic 1, Pic 2 are so on based on the qty of attachments on that email and if only one attachment then it does not add anything else to the file name that is already coded in this code?
Thanks!!!!!!
Bookmarks