I need to organise my mailbox in order not to lost a specific email when deduplicate the Inbox sub folder. The issue i have is that i receive every single day at specific time two emails in my Inbox with the same name, but with different files in them as an attachments. The emails are moved from Inbox to a sub folder by rule. I need one of the emails to be moved to a concrete folder, but since the mails have the same subject name and body, i can't use a rule to do that. So i have a macro that i assume, have to do the job but it doesn't. Also since the mails arrived every morning, i can't check my macro works, and i dont know how to modify the code to check the entire subfolder and executes the task for emails already inside. The folder structure i have : Inbox ---> Receiving folder name: "Meteologica SA Power Forecast"---> Target folder name: "Meteologica Hrabrovo Forecast". Basically i need an email, allways have file attachment in it with name having this part "-wind-power-forecast-HrabrovoWind(.csv)" to be moved from "Meteologica SA Power Forecast" sub folder, to the "Meteologica Hrabrovo Forecast" target sub folder of my Outlook Inbox. I just don't have the knowledge to make it works...Can you help me with that, please? Here's the code i have but i don't know what's wrong:
Private Sub Application_Startup()
Set objMails = Outlook.Application.Session.GetDefaultFolder(olFolderInbox).Items
End Sub
Sub Copy_Hrabrovo()
Dim ns As NameSpace
Dim olInboxFolder As MAPIFolder, olSubFolder As MAPIFolder
Dim msg As MailItem
Dim objAttachments As Outlook.Attachments
Dim objAttachment As Outlook.Attachment
Dim strAttachmentName As String
Set ns = GetNamespace("MAPI")
Set olInboxFolder = ns.GetDefaultFolder(olFolderInbox)
Set olSubFolder = olInboxFolder.Folders("Meteologica SA Power Forecast")
If TypeOf Item Is MailItem Then
Set objMail = Item
Set objAttachments = objMail.Attachments
If objAttachments.Count > 0 Then
For Each objAttachment In objAttachments
strAttachmentName = objAttachment.DisplayName
Set objInboxFolder = Application.Session.GetDefaultFolder(olFolderInbox)
If InStr(LCase(strAttachmentName), "-wind-power-forecast-HrabrovoWind") > 0 Then
Set objTargetFolder = objInboxFolder.Folders("Meteologica Hrabrovo Forecast")
End If
Next
obfMail.Move objTargetFolder
End If
End If
Set olSubFolder = Nothing
Set olInboxFolder = Nothing
Set ns = Nothing
End Sub