Hello,
Ive been trying to find a macro that will move emails with xls or xlsx attachments into a subfolder of the inbox called Spreadsheets.
I have multiple mailboxes and only want this to run on a single mailbox, so I believe using a rule to run a script on a specific inbox is the best way to go. Ive enabled the option but editing the registry so I can select the "run a script" rule, but the examples I have found online all give me various errors and im nowhere near experienced enough to resolve the issue.
This is the code I currently have, amended from an example I found online:
Sub MercedesExcel2(item As Outlook.MailItem)
Dim olkAtt As Outlook.Attachment
'Check each attachment
For Each olkAtt In item.Attachments
'If the attachment's file name ends with .xls or xlsx
If Right(LCase(olkAtt.FileName), 5) = ".xlsx" Then
'Move the message to Spreadsheets folder
item.Move Session.GetDefaultFolder(olFolderInbox).Folders("Spreadsheets")
ElseIf Right(LCase(olkAtt.FileName), 4) = ".xls" Then
item.Move Session.GetDefaultFolder(olFolderInbox).Folders("Spreadsheets")
Exit For
End If
Next
Set olkAtt = Nothing
End Sub
When I receive an email with the specified attachments, I get an object cannot be found error and it highlights the line:
item.Move Session.GetDefaultFolder(olFolderInbox).Folders("Spreadsheets")
Im not sure what is wrong with it, as the folder does exist as a subfolder of the inbox.
Any help would be much appreciated.
Thanks
Steve