A Better way to Run Scripts in Rule Wizard
- From: ct60 <ct60@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 15 Aug 2006 12:39:02 -0700
Hello again -
You may note that I posted before "Funky Errors running scripts from
Outlook". The strange thing there was for no apparent reason the rule would
fail BEFORE THE CODE EVEN RAN (oh my!)
Anyway, a collegue discovered this posting in MS Knowledgebase which seems
to avoid the problem. The link is:
http://support.microsoft.com/kb/292063/en-us
Here's the code:
In ThisOutlook Session Module:
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)
' <or whatever you want to do>
' 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@xxxxxxxxxxxx"
' Send it
myForward.Send
End If
End If
End Sub
This code works really well and does not have the problemthat I encountered
trying to directly run a script from Rules Wizard.
Thought you all should know.
Chris (ct60)
.
- Prev by Date: Re: Public calendar form used to send calendar event
- Next by Date: Re: Programmatically accessing Exchange shared and public folders
- Previous by thread: Public calendar form used to send calendar event
- Next by thread: Re: Distributing VBA Projects in Enterprise Scenario
- Index(es):
Relevant Pages
|