Outlook: VBA code automatically forward Unread email to another mailbox

Hi experts,

We have Outlook 2007 and Exchange 2007 in our org, there is a request to be able to forward all Unread emails from a mailbox to a different mailbox after 1 day or so, and it'll run automatically or scheduled task.

I've searched around but haven't seen a way to do this with Transport rules or Outlook rules.

I think it probably can be done by writing some VBA codes in Outlook to accomplish. If so, could anyone help or guide me how to do that? I know little to nothing about VBA

Is this possible?
Who is Participating?
Chris BottomleyConnect With a Mentor Commented:
A bit of code to actually call a macro is as follows:

Dim objOL
Dim ctl
Dim cbr
Const msoControlButton = 1
Dim shell
    Set shell = CreateObject("wscript.shell")
    shell.Run "outlook.exe"
    Set objOL = CreateObject("Outlook.Application")
    Set cbr = objOL.ActiveExplorer.CommandBars("Standard")
    Set ctl = cbr.Controls.Add(msoControlButton)
    ctl.OnAction = "checkold"
'    ctl.Parameter = "fred"

Open in new window

check old needs to be a button in outlook that runs some code to do what you want.  A  piece of code to pick up any emails in the inbox that are unread and older than 1 day would be:

Sub send24()
Dim strFilter As String
Dim inboxItems As Items
Dim unreadItems As Items
    strFilter = "[received] <= '" & Format(DateAdd("h", -24, Now()), "ddddd h:nn AMPM") & "'"
    Set inboxItems = Application.Session.GetDefaultFolder(olFolderInbox).Items.Restrict(strFilter)
    strFilter = "[Unread] = True"
    Set unreadItems = inboxItems.Restrict(strFilter)
        For Each itm In unreadItems
            With itm.Forward
                .To = "fred@fred.com"
                .Subject = "Delayed response ... please process"
            End With
End Sub

Open in new window

send24 is the code that in this case is executed by the button check old as called  by the script

Chris BottomleyCommented:
Whilst it is possible using vba this would require the outlook client to be active ... Assuming so then we should be able to work something.

tnguyenWIRBAuthor Commented:
Hi Chris,

I guess so, if there's no other way such as Open Outlook, run the script, send unread message, close Outlook.
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Chris BottomleyCommented:
We could do it as a scheduled task for example hourly to run a script that does the business?
tnguyenWIRBAuthor Commented:
Yes, I was thinking about that too.

I forgot to say, I'd like to forward only the external emails and unread, not internal ones.

tnguyenWIRBAuthor Commented:
Sorry for the late response Chris, it was a long weekend for me :)

We had to modify the script a bit for our needs but it worked,

Thank you for your help,
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.