Beginner Needs VBA Help in Modifying Code

C

Cody

I am using Outlook 2003 and want to do the following:

Email received between 6 pm to 9 am is forwarded to (e-mail address removed)
Email received between Friday @ 6pm to Monday @ 9 am is forwarded to
(e-mail address removed)
Email received between 9am to 6pm is forwarded to (e-mail address removed)

I have looked on the web and found the following code on the MS website; but
unfortunately I am not sure where I am suppose to modify it. If you can
give me any guidance, I would appreciate it.

********

Public WithEvents myOlItems As Outlook.Items


Public Sub Application_Startup()

' Reference the items in the Inbox. Because myOlItems is declared
' "WithEvents" the ItemAdd event will fire below.
Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items

End Sub


Private Sub myOlItems_ItemAdd(ByVal Item As Object)

' If it's currently not between 9:00 A.M. and 5:00 P.M.
If Time() < #9:00:00 AM# Or Time() > #5:00:00 PM# Then

' Check to make sure it is an Outlook mail message, otherwise
' subsequent code will probably fail depending on what type
' of item it is.
If TypeName(Item) = "MailItem" Then

' Forward the item just received
Set myForward = Item.Forward

' Address the message
myForward.Recipients.Add "(e-mail address removed)"

' Send it
myForward.Send

End If

End If

End Sub

********
Thanks...Cody
 
M

Michael Bauer [MVP - Outlook]

There's already the code for items received between 5pm and 9am. If you want
to add another condition, you can use the ElseIf statement like this:

If ... Then
...
ElseIf ... Then
...
End If

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool
: VBOffice Reporter for Data Analysis & Reporting
: <http://www.vboffice.net/product.html?pub=6&lang=en>


Am Thu, 24 Sep 2009 09:54:01 -0700 schrieb Cody:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top