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.
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.