Solved

Macro for Outlook email forwarding

Posted on 2008-10-13
6
897 Views
Last Modified: 2010-04-21
I have a user that needs an automatiion system for a mailbox.  If an email is sent to this mailbox it should forward the email to 1 of 4 users in the company and preferably  cc the manager as well.   eg:  I have users A,B,C,D when an email is sent to the mailbox it must deliver to user A, the next time it must deliver to user B etc... sort of a round robin delivery system?
0
Comment
Question by:InoAdmin
  • 3
  • 2
6 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 22709802
Hi, InoAdmin.

The code below implements what you described.  Follow these instructions to use it.

1.  Start Outlook
2.  Click Tools->Macro->Visual Basic Editor
3.  If not already expanded, expand Microsoft Office Outlook Objects and click on Module1
4.  Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook's VB Editor window
5.  Edit the code as needed.  I included comments wherever something needs to or can change
6.  Click the diskette icon on the toolbar to save the changes
7.  Close the VB Editor
8.  Click Tools->Macro->Security
9.  Set the Security Level to Medium
10. Close Outlook
11. Start Outlook
12. Create a rule that fires for the messages you want to forward
13. Set the rule's action to "run a script" and select this script as the one to run

The script uses a note to keep track of the next user to send to.  The script creates the note if it does not exist.  Deleting the note will simply start the round robin process over at user 1.

Sub RoundRobin(Item As Outlook.MailItem)
    Dim olkForward As Outlook.MailItem, olkNote As Outlook.NoteItem, strBody As String, intIndex As Integer
    On Error Resume Next
    Set olkNote = Session.GetDefaultFolder(olFolderNotes).Items.Find("[Subject]='RoundRobin'")
    If TypeName(olkNote) <> "NoteItem" Then
        Set olkNote = Application.CreateItem(olNoteItem)
        olkNote.Body = "RoundRobin" & vbCr & 1
        olkNote.Save
    End If
    On Error GoTo 0
    strBody = Replace(olkNote.Body, "RoundRobin" & vbCr, "")
    intIndex = CInt(strBody)
    Set olkForward = Item.Forward
    Select Case intIndex
        Case 1
            'Change the email address on the following line'
            olkForward.Recipients.Add "user1@company.com"
        Case 2
            'Change the email address on the following line'
            olkForward.Recipients.Add "user2@company.com"
        Case 3
            'Change the email address on the following line'
            olkForward.Recipients.Add "user3@company.com"
        Case 4
            'Change the email address on the following line'
            olkForward.Recipients.Add "user4@company.com"
    End Select
    intIndex = intIndex + 1
    If intIndex > 4 Then
        intIndex = 1
    End If
    olkNote.Body = "RoundRobin" & vbCr & intIndex
    olkNote.Save
    Set olkNote = Nothing
    'Change the email address on the following line'
    olkForward.CC = "manager@company.com"
    olkForward.Recipients.ResolveAll
    olkForward.Display
    Set olkForward = Nothing
End Sub

Open in new window

0
 

Author Comment

by:InoAdmin
ID: 22710118
I gave this a try but it needs a bit of fine tuning.  When an email is sent to the mailbox the new message window opens with the correct recipients displayed in the TO and CC fields however it does not send the message, it just sits in the new message window?  Is there also a way to implement this without having to have the mailbox open in Outlook all the time?
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 22710159
Sorry, forgot to change one line from when I was testing.  Change the word Display to Send on line #38.

No, there's no way to implement this without having the mailbox open all the time.  That would require an event-sink running on the Exchange server.  Event-sinks are like macros that run at the server.  However, they are more difficult to write and poorly written or buggy event-sink could bring the whole server down.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Closing Comment

by:InoAdmin
ID: 31505787
Thanks for your help and quick response, much appreciated
0
 
LVL 76

Expert Comment

by:David Lee
ID: 22710249
You're welcome.  Glad I could help.
0
 

Expert Comment

by:obi-won
ID: 23399945
Does this require using an MS exchange server or can it work with a stand alone outlook 2007 using a pop3 account?
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to dynamically set the form action using jQuery.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question