View Single Post
 
Old 06-22-2011, 12:03 PM
Dav Dav is offline Windows XP Office 2007
Novice
 
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
'PUT THE EXTERNAL EMAIL ADDRESS YOU WANT TO USE ON THE NEXT LINE
objMail.To = "myemail.com"
objMail.Send
Set objItem = Nothing
Set objMail = Nothing
End If
End If
Next
End Sub

Function IsNothing(Obj)
If TypeName(Obj) = "Nothing" Then
IsNothing = True
Else
IsNothing = False
End If
End Function
'END CODE
Reply With Quote