Consulting

Results 1 to 5 of 5

Thread: Firing a script via a rule

  1. #1
    VBAX Newbie
    Joined
    Feb 2006
    Posts
    2
    Location

    Firing a script via a rule

    Hi there. I'm definitely not a coder, but I've been working with one of our developers to get some alerting via our monitoring software. At the moment we are using Outlook rules to distribute the alerts, this works well but has its limitations, eg we cannot alert based on time received. To get around that problem we came up with the script below. The problem is that this will not fire as the incoming message is re-routed before hitting the inbox. How can i add this script as a macro to fire before all other rules?
    Thanks for any help

    Mike.

    [VBA] Public WithEvents myOlItems As Outlook.Items
    Private Sub myOlItems_ItemAdd(ByVal Item As Object)
    On Error GoTo Error_Trap

    ' If it's currently not between 7:00 A.M. and 6:00 P.M.
    If Time() < #7:00:00 AM# Or Time() > #6: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.Body = StripHeader(myForward.Body)
    myForward.Recipients.Add "[sms:MobileNumber]"

    ' Send it
    myForward.Send
    End If
    End If

    Exit Sub

    Error_Trap:
    ' Do nothing
    End Sub
    Public Function StripHeader(ByVal Body As String) As String
    On Error GoTo Error_Trap

    ' Tweak interations with this constant
    Const C_RETURNS As Integer = 7

    Dim I As Integer
    Dim intPosition As Integer

    I = 0

    For intPosition = 1 To Len(Body)
    If I = C_RETURNS Then Exit For
    If Asc(Mid(Body, intPosition, 1)) = 10 Then I = I + 1
    Next

    StripHeader = Mid(Body, intPosition)

    Exit_Point:
    Exit Function

    Error_Trap:
    ' Return original message if an error is encountered
    StripHeader = Body
    End Function

    [/VBA]
    Last edited by geekgirlau; 02-12-2006 at 05:12 PM. Reason: Put code in VBA tags

  2. #2
    VBAX Newbie
    Joined
    Feb 2006
    Posts
    2
    Location

    Firing a script via a rule

    Hi there. I'm definitely not a coder, but I've been working with one of our developers to get some alerting via our monitoring software. At the moment we are using Outlook rules to distribute the alerts to various teams, this works well but has its limitations, eg we cannot alert based on time received. To get around that problem we came up with the script attached. The problem is that this will not fire as the incoming message is re-routed before hitting the inbox (it works perfectly if there aren't any rules defined). How can i add this script as a macro to fire before all other rules?
    Thanks for any help

    Mike.

  3. #3
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    Hi emcee303,

    I've edited your post to put the code in VBA tags - it makes it much easier to work out what the code is doing.

    When inserting code in a post, highlight all the code and click on the "VBA" button.

  4. #4
    VBAX Master XLGibbs's Avatar
    Joined
    Jan 2006
    Location
    state of confusion, but vacation in denial
    Posts
    1,315
    Location
    Mike, we got keep it to one thread to avoid confusion. Since this is a duplicate topic and subject, and the code appears in the other post without needing to open the attachment I have simply merged the two threads.

    Thanks

    Pete
    PS. Sorry I have not worked out a solution yet...
    If you have posted the same question at multiple forums, please read this IMPORTANT INFO.

    Please use the thread tools to mark your thread Solved


    Please review the Knowledge Base
    for samples and solutions , or to submit your own!




  5. #5
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi,

    Use the NewMailEx event to handle your new Email instead of a rule! (and if neccesary let it reroute your mail)

    Here I put down a example:
    http://vbaexpress.com/forum/showthre...ight=NewMailEx

    HTH!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

Posting Permissions

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