Frederick Hung
New Member
- Outlook version
- Outlook 2013 64 bit
- Email Account
- Exchange Server 2013
Hi Diane, I have written an Outlook script to process incoming emails that meets the Outlook rules. The script will reformat the subject (based on the attachment), modify the body and then fwd the email to specified recipients.
It's been working well until recently we face a challenge, the same email may come from 2 different senders, and my script will process them individually which means it will Output to recipient twice. Is there any way to stop the script from processing duplicate?
One thing I can think of is to check the attachment name which is saved. Below is my current script, how can I enhance it to check for duplicate? Appreciated your help in advance.
Sub SendNew_Attach(Item As Outlook.MailItem)
Dim objMsg As MailItem
Set objMsg = Application.CreateItem(olMailItem)
If Item.Attachments.Count > 0 Then
Dim attCount As Long
Dim strFile As String
Dim sFileType As String
Dim strFolderpath As String
Dim objAttachments As Outlook.Attachments
Set objAttachments = objMsg.Attachments
attCount = Item.Attachments.Count
For i = attCount To 1 Step -1
strFile = Item.Attachments.Item(i).FileName
sFileType = LCase$(Right$(strFile, 4))
Select Case sFileType
Case "xlsx"
' do something if the file types are found
' this code fwd the attachment and change the email subejct n body
strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16)
strFolderpath = strFolderpath & "\OLAttachments\"
strFile = strFolderpath & strFile
' Save the attachment as a file.
Item.Attachments.Item(i).SaveAsFile strFile
End Select
Next i
End If
It's been working well until recently we face a challenge, the same email may come from 2 different senders, and my script will process them individually which means it will Output to recipient twice. Is there any way to stop the script from processing duplicate?
One thing I can think of is to check the attachment name which is saved. Below is my current script, how can I enhance it to check for duplicate? Appreciated your help in advance.
Sub SendNew_Attach(Item As Outlook.MailItem)
Dim objMsg As MailItem
Set objMsg = Application.CreateItem(olMailItem)
If Item.Attachments.Count > 0 Then
Dim attCount As Long
Dim strFile As String
Dim sFileType As String
Dim strFolderpath As String
Dim objAttachments As Outlook.Attachments
Set objAttachments = objMsg.Attachments
attCount = Item.Attachments.Count
For i = attCount To 1 Step -1
strFile = Item.Attachments.Item(i).FileName
sFileType = LCase$(Right$(strFile, 4))
Select Case sFileType
Case "xlsx"
' do something if the file types are found
' this code fwd the attachment and change the email subejct n body
strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16)
strFolderpath = strFolderpath & "\OLAttachments\"
strFile = strFolderpath & strFile
' Save the attachment as a file.
Item.Attachments.Item(i).SaveAsFile strFile
End Select
Next i
End If