Solved

Outlook: VBA code automatically forward Unread email to another mailbox

Posted on 2012-03-15
6
1,658 Views
Last Modified: 2012-03-20
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?
0
Comment
Question by:tnguyenWIRB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 37729662
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.

Chris
0
 
LVL 1

Author Comment

by:tnguyenWIRB
ID: 37729877
Hi Chris,

I guess so, if there's no other way such as Open Outlook, run the script, send unread message, close Outlook.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 37730718
We could do it as a scheduled task for example hourly to run a script that does the business?
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 1

Author Comment

by:tnguyenWIRB
ID: 37730749
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.

Thanks,
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 500 total points
ID: 37732787
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"
    ctl.Execute
    ctl.Delete

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"
                .Display
            End With
        Next
    
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
0
 
LVL 1

Author Comment

by:tnguyenWIRB
ID: 37743202
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,
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

733 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