View Full Version : [SOLVED:] Outlook 2013 Rules Manually Run on User Selected Emails
aworthey
09-27-2016, 07:09 AM
Hello,
I'm looking for a way to trigger an Outlook rule either manually on emails I select or automatically by my dragging and dropping into a sub folder.
Essentially, I want to trigger a macro on specific emails that I choose. I can't just specify the rule to run by email address because not every email from an address would need to be processed.
Is anyone aware if something like this is possible?
aworthey
09-27-2016, 07:31 AM
I just found this code. I believe this could be adapted to call my macro to run on messages that arrive in my subfolder.
Public WithEvents FolderItems As Outlook.Items
Private Sub Application_Startup()
Set FolderItems = Session.GetDefaultFolder(olFolderInbox).Folders("DONE").Items
End Sub
Private Sub FolderItems_ItemAdd(ByVal Item As Object)
On Error Resume Next
If Item.UnRead Then
Item.UnRead = False
Item.Save
End If
End Sub
aworthey
09-28-2016, 10:23 AM
So, this code below seems to work well if the email that is dropped into the folder is from within my own Microsoft Exchange account, but it will not trigger if the email address is from someone else.
Any ideas?
Public WithEvents FolderItems As Outlook.Items
Private Sub Application_Startup()
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim olFolder As Outlook.MAPIFolder
Dim objWatchFolder As Outlook.Folder
Dim objOwner As Recipient
Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
Set objOwner = objNS.CreateRecipient("appengineer@kohler.com")
objOwner.Resolve
Set olFolder = objNS.GetSharedDefaultFolder(objOwner, olFolderInbox)
Set objWatchFolder = olFolder.Folders("Info Setup")
Set FolderItems = objWatchFolder.Items
Set objWatchFolder = Nothing
End Sub
Private Sub FolderItems_ItemAdd(ByVal Item As Object)
On Error Resume Next
Call InfoEmailScrub.CopyInfoToExcel(Item)
End Sub
skatonni
09-28-2016, 12:28 PM
You may see an error to fix if you remove On Error Resume Next. http://www.cpearson.com/excel/DebuggingVBA.aspx
In general until you know how to use On Error GoTo 0 you have to stop using On Error Resume Next. http://www.cpearson.com/Excel/ErrorHandling.htm
aworthey
09-28-2016, 12:31 PM
Update: This code works perfectly. There was an Outlook mail object in the InfoEmailScrub code that wasn't set properly which caused the error. Thanks!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.