klornpallier
Technical User
I have code that saves outlook attachments to network locations based on the attachment filname. The code for this works fine but I need the delete all the items out of the Subfolder afterwards. The code is below:
' Declare variables
Dim ns As NameSpace
Dim Inbox As MAPIFolder
Dim SubFolder As MAPIFolder
Dim Item As Object
Dim Atmt As Attachment
Dim FileName As String
Dim PhaseNo As String
Dim Slash As String
Dim Trust As String
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim varResponse As VbMsgBoxResult
'Allocate Folders
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
Set SubFolder = Inbox.Folders("Migration Reports") ' Enter correct subfolder name.
i = 0
' Check subfolder for messages and exit of none found
If SubFolder.Items.Count = 0 Then
MsgBox "There are no messages in the Migration Reports folder.", vbInformation, _
"Nothing Found"
Exit Sub
End If
' Check each message for attachments
For Each Item In SubFolder.Items
For Each Atmt In Item.Attachments
' Check filename of each attachment and save if it has "xls" extension
If Mid(Atmt.FileName, 5, 3) = "CER" Then
Trust = Mid(Atmt.FileName, 10, 3)
k = k + 1
ElseIf Mid(Atmt.FileName, 4, 1) = "_" Then
Trust = Left(Atmt.FileName, 3)
i = i + 1
End If
If Trust = "388" Or Trust = "545" Or Trust = "631"
Or Trust = "504" Or Trust = "775" Then
PhaseNo = "4"
End If
Slash = "\"
' This path must exist! Change folder name as necessary.
FileName = "\\isesrfiler\NHS_HR-Pay\Data Migration\Data Management\DM Testing\Main Pilot\Phase " & PhaseNo & Slash & Trust & Slash & Atmt.FileName
Atmt.SaveAsFile FileName
Next Atmt
Next Item
I've tried inserting Item.Delete after Next Atmt & it only deletes some of the mails. Help?
' Declare variables
Dim ns As NameSpace
Dim Inbox As MAPIFolder
Dim SubFolder As MAPIFolder
Dim Item As Object
Dim Atmt As Attachment
Dim FileName As String
Dim PhaseNo As String
Dim Slash As String
Dim Trust As String
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim varResponse As VbMsgBoxResult
'Allocate Folders
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
Set SubFolder = Inbox.Folders("Migration Reports") ' Enter correct subfolder name.
i = 0
' Check subfolder for messages and exit of none found
If SubFolder.Items.Count = 0 Then
MsgBox "There are no messages in the Migration Reports folder.", vbInformation, _
"Nothing Found"
Exit Sub
End If
' Check each message for attachments
For Each Item In SubFolder.Items
For Each Atmt In Item.Attachments
' Check filename of each attachment and save if it has "xls" extension
If Mid(Atmt.FileName, 5, 3) = "CER" Then
Trust = Mid(Atmt.FileName, 10, 3)
k = k + 1
ElseIf Mid(Atmt.FileName, 4, 1) = "_" Then
Trust = Left(Atmt.FileName, 3)
i = i + 1
End If
If Trust = "388" Or Trust = "545" Or Trust = "631"
Or Trust = "504" Or Trust = "775" Then
PhaseNo = "4"
End If
Slash = "\"
' This path must exist! Change folder name as necessary.
FileName = "\\isesrfiler\NHS_HR-Pay\Data Migration\Data Management\DM Testing\Main Pilot\Phase " & PhaseNo & Slash & Trust & Slash & Atmt.FileName
Atmt.SaveAsFile FileName
Next Atmt
Next Item
I've tried inserting Item.Delete after Next Atmt & it only deletes some of the mails. Help?