+ Reply to Thread
Results 1 to 12 of 12

How to forward or redirect an outlook email based on count one at a time to one user

  1. #1
    Forum Contributor
    Join Date
    06-04-2011
    Location
    Hyderabad
    MS-Off Ver
    Excel 2007
    Posts
    108

    Question How to forward or redirect an outlook email based on count one at a time to one user

    Hi,

    As I am new to the macros using VBA, having a query to share with and badly needed to survive..

    Daily i would receive n number of mails to my inbox, based on the count i have to forward or redirect the mails to three recipients of my contacts.

    Ex: if in inbox mail count is three (3), may be same subject line or different subject line. Those three mails should be send to three persons as "one email to A, second to B, third mail to C". This process should continue when there is three count in inbox. Please anyone can do the needful..

    Thank you in advance.

    Thanks & Regards
    Chaitanya A
    Thanks & Regards
    Chaitanya A

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: How to forward or redirect an outlook email based on count one at a time to one u

    I got so far in creating some code to perform the forwarding but then realised that you hadn't said what you wanted to happen to the original e-mails with forwarded copies.
    I guess that the options are to move them to another folder or delete them or just mark them as read?
    Martin

  3. #3
    Forum Contributor
    Join Date
    06-04-2011
    Location
    Hyderabad
    MS-Off Ver
    Excel 2007
    Posts
    108

    Re: How to forward or redirect an outlook email based on count one at a time to one u

    Quote Originally Posted by mrice View Post
    I got so far in creating some code to perform the forwarding but then realised that you hadn't said what you wanted to happen to the original e-mails with forwarded copies.
    I guess that the options are to move them to another folder or delete them or just mark them as read?
    Hi Mrice,

    Thanks for the reply..
    I am sorry for not mentioning what exactly after the mail forward.. that particular mail should be "marked as read".
    I hope hear you soon.

    thanks in advance.

    Chaitanya A

  4. #4
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: How to forward or redirect an outlook email based on count one at a time to one u

    The following code appears to work for me when pasted into the ThisOutLookSession tab in the Outlook VBA editor.

    Please Login or Register  to view this content.
    It makes use of the Unread Mail search folder to determine how many unread mail items there are and sets the to read hence removing them from the Search Folder.

    As set up, it does require that the Search folder is not picking up any other unread messages that you might not want to process.

    You could probably adapt this to a different search folder with different criteria if required.
    Last edited by mrice; 08-21-2011 at 03:02 PM.

  5. #5
    Forum Contributor
    Join Date
    06-04-2011
    Location
    Hyderabad
    MS-Off Ver
    Excel 2007
    Posts
    108

    Re: How to forward or redirect an outlook email based on count one at a time to one u

    Hi Mrice,

    Great!!!! It is working...!!
    Thanks alot for the code...
    A small help, if you wont' mind, how to mark the read mail with flag or to categorize..

    Help me out...

  6. #6
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: How to forward or redirect an outlook email based on count one at a time to one u

    Try this

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    06-04-2011
    Location
    Hyderabad
    MS-Off Ver
    Excel 2007
    Posts
    108

    Re: How to forward or redirect an outlook email based on count one at a time to one u

    Hi Mrice,


    If oFolder.Items.count >= 8 Then

    at this line of code while executing im getting an error as..
    Run-time error '91':
    Object variable or With block variable not set

    could you please help me out figuring the solution..

    eagerly waiting for the reply..
    Last edited by romperstomper; 08-24-2011 at 07:16 AM.

  8. #8
    Forum Contributor
    Join Date
    06-04-2011
    Location
    Hyderabad
    MS-Off Ver
    Excel 2007
    Posts
    108

    Re: How to forward or redirect an outlook email based on count one at a time to one u

    Quote Originally Posted by anchuri_chaitanya View Post
    Hi Mrice,


    If oFolder.Items.count >= 8 Then

    at this line of code while executing im getting an error as..
    Run-time error '91':
    Object variable or With block variable not set

    could you please help me out figuring the solution..

    eagerly waiting for the reply..
    Hi Mrice,
    Hope, not irritating you..
    When i tried the code in my regular outlook, it is worked, but when trying to execute in the outlook maintained by server is showing the error on and as..
    If oFolder.Items.count >= 8 Then

    at this line of code while executing im getting an error as..
    Run-time error '91':
    Object variable or With block variable not set

    could you please help me out figuring the solution..
    Is there any chance to write this code in a module and can execute than in this outlook session..

    eagerly waiting for the reply..

  9. #9
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: How to forward or redirect an outlook email based on count one at a time to one u

    Is there an unread items search folder on the server version?

    The error suggests that the code is not finding one.

  10. #10
    Forum Contributor
    Join Date
    06-04-2011
    Location
    Hyderabad
    MS-Off Ver
    Excel 2007
    Posts
    108

    Re: How to forward or redirect an outlook email based on count one at a time to one u

    Quote Originally Posted by mrice View Post
    Is there an unread items search folder on the server version?

    The error suggests that the code is not finding one.
    Unread search folder...??
    The outlook is mapped in my machine as separate (Default) and the one has inbox where all the mails comes into..
    Daily Hundreds of mails comes in..
    can't we run the code or make the code in a module that which makes the same sense..?
    Please help me..

  11. #11
    Forum Contributor
    Join Date
    06-04-2011
    Location
    Hyderabad
    MS-Off Ver
    Excel 2007
    Posts
    108

    Re: How to forward or redirect an outlook email based on count one at a time to one u

    Quote Originally Posted by mrice View Post
    Is there an unread items search folder on the server version?

    The error suggests that the code is not finding one.
    Hi mrice,

    Private Sub Application_NewMail()
    Dim MyInBox As Folder
    Dim oNS As NameSpace
    Dim myItem As Outlook.MailItem
    Dim N As Integer
    Dim colStores As Outlook.Stores
    Dim oStore As Outlook.Store
    Dim oSearchFolders As Outlook.Folders
    Dim olFolder As Outlook.Folder
    Dim i As Long
    Dim ObjOutItem As Outlook.MailItem
    Dim ObjOutName As Outlook.NameSpace
    Dim ObjOutInbox As Outlook.MAPIFolder
    Dim ObjOutApp As New Outlook.Application

    'set the outlook objects
    Set ObjOutApp = CreateObject("Outlook.Application")
    Set ObjOutName = ObjOutApp.GetNamespace("MAPI")
    Set ObjOutInbox = ObjOutName.GetDefaultFolder(olFolderInbox)

    'If ObjOutInbox.Items.count = 0 Then
    ' MsgBox "Inbox is Empty", vbInformation, "Nothing Found"
    ' Exit Sub
    'End If
    'Set colStores = Application.Session.Stores
    'Set oStore = colStores(1)
    'Set oSearchFolders = oStore.GetSearchFolders
    'For Each olFolder In oSearchFolders
    ' If olFolder.Name = "Unread Mail" Then Exit For
    'Next

    If ObjOutInbox.Items.count >= 8 Then

    For N = 1 To 8

    'Set myItem = olFolder.Items(1).Forward
    Set ObjOutItem = ObjOutInbox.Items.Item(N).Forward
    Select Case N
    Case Is = 1
    ObjOutItem.Recipients.Add "[email protected]"

    Case Is = 2
    ObjOutItem.Recipients.Add "[email protected]"

    Case Is = 3
    ObjOutItem.Recipients.Add "[email protected]"

    End Select

    ObjOutInbox.Items(N).FlagIcon = 5
    ObjOutInbox.Items(N).Save

    ObjOutInbox.Items(N).UnRead = False
    ObjOutItem.Send
    DoEvents
    Next N

    End If

    End Sub

    I have tried modifying the code and able to run the above placed code. The thing is it is not getting looped. As three mails only getting forwarded and flagged. if the mails are above three and lets say upt 100, only three is forwarded and if i try to run once again the read and flagged mails are getting forwarded.

    I knew that your help is putting me in to big deals.
    help me out, please,..

  12. #12
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: How to forward or redirect an outlook email based on count one at a time to one u

    Hi

    My original code made use of a search folder to identify unread e-mails. The alternative was to scan the inbox for unread e-mails which could take some time if your inbox contains many items (like mine ).

    I don't think that the current problems are caused by the location of the code. I need to repeat my question regarding whether the server version of Outlook has an Unread Mail Search folder - your local version obviously did. You will find it towards the bottom of the folder tree in the Mail Folders pane on the left hand side of the screen. If there is not one, you will need to create one on the server version with a right click.

    Additionally, the code is designed to run in steady state starting with no unread mails and only doing anything substantial when the count gets to three. It does not deal well with a large backlog as it just processes three at a time when a new mail arrives (i.e. it only reduces the backlog by 3 - 1 = 2 mail items.)

    I hope that this helps.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1