PDA

View Full Version : Auto forward macro/rule



otictac1
08-19-2008, 11:51 AM
Hello everyone,

I am attempting to create a rule/macro that autoforwards everything I get after a certain time to another email address. I've more or less successfully done that with this:

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 "myaddress@mydomain.com"
' Send it
myForward.Send
End If
End If
End Sub


However, there is a problem. When this does its voodoo and forwards the email, it leaves an item in my sent emails saying that it was forwarded. However, I noticed that if you just create a rule that forwards things automatically it doesn't create a forward in your sent item. Can someone show me how to modify this code so that I can create a rule that runs a script which forwards things received after a certain time?
I'm hoping that will not create the forward in my sent items.

mavol
11-10-2008, 02:27 PM
What you have at least works for me. Thanks!!!!

moremeba
11-12-2008, 02:33 PM
Hi Otictac1, i tried your code on my outlook 2002 and it didnt work unfortunatly. The Macro you created is exactly what i am after to forward my work emails home outside of my normal office hours 9-5pm. Can you think of where i may be going wrong with the code. I am new to vba, so any help would be greatly appreciated.
Thanks in advance

Moremeba