I have the following VBA code working perfectly apart from the Att.Delete!
In summary, I want to save incoming mail attachments* to a folder* then delete the attachment from the incoming mail - Att.SaveAsFile works perfectly, but Att.Delete doesn't do anything! - any ideas please? ...
* as defined in the code
Public WithEvents olItems As Outlook.Items
Private Sub Application_NewMail()
End Sub
Private Sub Application_Startup()
Set olItems = Session.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub olItems_ItemAdd(ByVal Item As Object)
Dim NewMail As Outlook.MailItem
Dim Atts As Attachments
Dim Att As Attachment
Dim strPath As String
Dim strName As String
If Item.Class = olMail Then
Set NewMail = Item
End If
Set Atts = Item.Attachments
If Atts.Count > 0 Then
For Each Att In Atts
If InStr(1, Att.FileName, "NEWINCIDENT", vbTextCompare) > 0 Then
strPath = "C:\Users\User\Documents\$$$ADAM\New_Incidents_Submitted\"
strName = Att.FileName
Att.SaveAsFile strPath & strName
Att.Delete
End If
Next
End If
End Sub
In summary, I want to save incoming mail attachments* to a folder* then delete the attachment from the incoming mail - Att.SaveAsFile works perfectly, but Att.Delete doesn't do anything! - any ideas please? ...
* as defined in the code
Public WithEvents olItems As Outlook.Items
Private Sub Application_NewMail()
End Sub
Private Sub Application_Startup()
Set olItems = Session.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub olItems_ItemAdd(ByVal Item As Object)
Dim NewMail As Outlook.MailItem
Dim Atts As Attachments
Dim Att As Attachment
Dim strPath As String
Dim strName As String
If Item.Class = olMail Then
Set NewMail = Item
End If
Set Atts = Item.Attachments
If Atts.Count > 0 Then
For Each Att In Atts
If InStr(1, Att.FileName, "NEWINCIDENT", vbTextCompare) > 0 Then
strPath = "C:\Users\User\Documents\$$$ADAM\New_Incidents_Submitted\"
strName = Att.FileName
Att.SaveAsFile strPath & strName
Att.Delete
End If
Next
End If
End Sub