Hey folks,
I ve got this code. It saves all pdf attachments from outlook folder and renames them in consequential order. However, what I want is that code renames them in the reverse sequence. Currently, it puts on the first item in inbox (sorted by date) the last number in folder and so on. I want the reverse sequence. The first one in the outlook inbox should get the first number in the sequence and so on..
I ve got this code. It saves all pdf attachments from outlook folder and renames them in consequential order. However, what I want is that code renames them in the reverse sequence. Currently, it puts on the first item in inbox (sorted by date) the last number in folder and so on. I want the reverse sequence. The first one in the outlook inbox should get the first number in the sequence and so on..
Private Sub cmdConnectToOutlook_Click()
Dim appOutlook As Outlook.Application
Dim ns As Outlook.NameSpace
Dim inbox As Outlook.MAPIFolder
Dim item As Object
Dim atmt As Outlook.Attachment
Dim filename As String
Dim i As Integer
Set appOutlook = GetObject(, "Outlook.Application")
Set ns = appOutlook.GetNamespace("MAPI")
Set inbox = ns.GetDefaultFolder(olFolderDrafts)
i = 0
m = 1
If inbox.Items.Count = 0 Then
MsgBox "There are no messages in the Inbox.", vbInformation, _
"Nothing Found"
Exit Sub
End If
For Each item In inbox.Items
For Each atmt In item.Attachments
If Right(atmt.filename, 3) = "pdf" Then
filename = atmt.filename
atmt.SaveAsFile "C:\Intel\Logs\" & m & ".pdf"
i = i + 1
m = m + 1
End If
Next atmt
Next item
MsgBox "Attachments have been saved.", vbInformation, "Finished"
Set atmt = Nothing
Set item = Nothing
Set ns = Nothing
End Sub
Last edited: