Consulting

Results 1 to 5 of 5

Thread: Outlook 2013 Rules Manually Run on User Selected Emails

  1. #1
    VBAX Regular
    Joined
    May 2016
    Posts
    73
    Location

    Outlook 2013 Rules Manually Run on User Selected Emails

    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?

  2. #2
    VBAX Regular
    Joined
    May 2016
    Posts
    73
    Location
    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

  3. #3
    VBAX Regular
    Joined
    May 2016
    Posts
    73
    Location
    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

  4. #4
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    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
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

  5. #5
    VBAX Regular
    Joined
    May 2016
    Posts
    73
    Location
    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!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •