Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Office > Outlook

LinkBack Thread Tools Display Modes
Old 06-22-2011, 12:03 PM
Dav Dav is offline Windows XP Office 2007
Join Date: Jun 2011
Posts: 1
Dav is on a distinguished road
Default Auto Forward Emails - Specific Time Periods Only

I want to auto forward by rule email messages after hours. Is it possible to create a rule that would forward emails with a specific criteria during a specific set of hours? I got this VB code from someone, but I get an error message saying bad syntex when it gets to the place I have put in bold and underlined. Any thoughts on what I can do?

Private WithEvents objInboxItems As Items

Private Sub Application_Startup()
Dim objNS As NameSpace
Set objNS = Application.GetNamespace("MAPI")
' instantiate Items collections for folders we want to monitor
Set objInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items
Set objNS = Nothing
End Sub

Private Sub Application_Quit()
' disassociate global objects declared WithEvents
Set objInboxItems = Nothing
End Sub

Private Sub objInboxItems_ItemAdd(ByVal Item As Object)
Dim olItems As Items, _
olItem As Object, _
olMailItem As MailItem, _
olAttachmentItem As Attachment, _
bolTimeMatch As Boolean
Set olItems = objInboxItems.Restrict("[Unread] = True")
For Each olItem In olItems
If olItem.Class = olMail Then
Set olMailItem = olItem
'Change the times on the next line to those you want to use
bolTimeMatch = (Time >= #6:00:00 PM#) And (Time <= #8:30:00 AM#)
If bolTimeMatch Then
Dim objMail As Outlook.MailItem
Set objItem = olMailItem
Set objMail = objItem.Forward
objMail.To = ""
Set objItem = Nothing
Set objMail = Nothing

End If
End If
End Sub

Function IsNothing(Obj)
If TypeName(Obj) = "Nothing" Then
IsNothing = True
IsNothing = False
End If
End Function
Reply With Quote
Please reply to this thread with any new information or opinions.

Thread Tools
Display Modes

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sent emails all have same date/time?? Confused Outlook 3 01-07-2011 06:52 AM
Outlook 2007 - Notifications if emails are unread after a specific amount of time? Robb Outlook 0 12-10-2010 10:18 AM
Code to auto-forward weekend messages Whang Outlook 0 06-16-2010 02:18 PM
Auto-Forward Read Reply timcar1 Outlook 0 10-13-2009 09:33 PM
Auto forward return receipt to Requestor sarav@msoutlook Outlook 0 12-09-2008 05:34 AM

All times are GMT -7. The time now is 02:51 PM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc. is not affiliated with Microsoft