Results 1 to 2 of 2
  1. #1
    New Lounger
    Join Date
    Sep 2005
    Thanked 0 Times in 0 Posts

    03: Rule to Forward Emails w/ time restrictions (O

    I want to create a rule in Outlook 2003 that will forward email from a certain address with certain words in the subject or body between 6pm - 8:00am Monday through Friday (and all day on Saturday and Sundays) to an another email address. I know outlook's built in rules can't do this, but I read I could do this with VB. I need help with the code.

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Silicon Valley, USA
    Thanked 94 Times in 90 Posts

    Re: 03: Rule to Forward Emails w/ time restriction

    This article supplies some background: Description of programming with Outlook rules (MSKB 324568). You can ignore everything after the heading "Outlook COM Add-in Rules."

    With respect to the day of week and time, it might be a bit easier to check the current day of week and time on the PC rather than checking the message's sent/received time. Here's a function you could use:

    <code>Function isAfterHours() As Boolean
    ' Set these to the appropriate hour (24 hours clock)
    Const dblStartOfDay As Double = 8
    Const dblEndOfDay As Double = 18
    ' Check current day and time and return appropriate value
    If Weekday(Now, vbMonday) > 5 Then
    ' It's the weekend
    isAfterHours = True
    If DateDiff("s", DateAdd("s", dblStartOfDay * 3600, Date), Now) < 0 Then
    ' It's early in the morning
    isAfterHours = True
    ElseIf DateDiff("s", DateAdd("s", dblEndOfDay * 3600, Date), Now) > 0 Then
    ' It's late in the evening
    isAfterHours = True
    isAfterHours = False
    End If
    End If
    End Function</code>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts