View Full Version : Screening incoming mail
ebolisa
03-07-2017, 02:37 AM
Hi,
I receive daily an email with 3 attached files, one of them having the ext .TXT.
The following code saves in a folder the 3 received attachments using a Rule.
I’d like to modify the code to store only the .TXT file.
How do I go by?
TIA
EDIT: Outlook 2007
Public Sub saveAttach(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
saveFolder = "c:\myAttFiles\"
For Each objAtt In itm.Attachments
objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
Set objAtt = Nothing
Next
End Sub
gmayor
03-07-2017, 08:46 AM
Public Sub saveAttach(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
saveFolder = "c:\myAttFiles\"
For Each objAtt In itm.Attachments
If Right(LCase(objAtt.fileName), 4) = ".txt" Then
objAtt.SaveAsFile saveFolder & "\" & objAtt.fileName
End If
Next
Set objAtt = Nothing
End Sub
ebolisa
03-08-2017, 02:54 AM
gmayor, thanks for getting back to me.
I tried your suggestion but still not filtering out the non wanted extensions. I changed the .txt to .TXT with no avail (just in case).
Nor did
UCase(objAtt.fileName), 4) = ".TXT"
helped.
gmayor
03-08-2017, 07:07 AM
It works fine here. Test it against a message in your inbox that has at least one txt format attachment with
Sub TestMacro()
Dim olMsg As MailItem
On Error Resume Next
Set olMsg = ActiveExplorer.Selection.Item(1)
saveAttach olMsg
lbl_Exit:
Exit Sub
End Sub
ebolisa
03-08-2017, 08:08 AM
18577I get a compiling error. It halts stating that there's no Sub or Function
EDIT:
My bad. It ran and saved the 3 files and not only one.
gmayor
03-08-2017, 10:49 PM
SaveAttach is the macro in my previous reply. It should be present for the test macro to find.
ebolisa
03-09-2017, 02:55 AM
Ok, I select the test email having three files with different extensions one of them being .TXT, go to Tools, Macro, Macro, Activate Macros and execute TestMacro.
I then go the folder and I find the three files whereas should be only one with the .TXT extension. So, the test macro is doing its job but, for some reason, the filtering is failing.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.