[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 170
  • Last Modified:

How to make a client rule trigger a subroutine

Dear experts,

Using Outlook 2003, I have set a rule that is fired when a email comes into my inbox with the word "test" in the subject. This should "run a script" (subroutine) called test() which is saved in ThisOutlookSession

Sub test(Item As Outlook.MailItem)
    MsgBox Item.Subject
End Sub

However this does not work.

What am i doing wrong? how can I get this to work?
0
m8rix
Asked:
m8rix
  • 3
  • 2
1 Solution
 
weellioCommented:
here's one i wrote for some other guy, you should be able to edit to do what you need

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_22702447.html 

added some extra stuff in there to be useful
assumes the following
c:\windows\temp exists
if you use the 'myfolder' variable, then folder "my folder" exists under the inbox




Sub DoStuff()
' Declare variables
    Dim ns As NameSpace
    Dim Inbox As MAPIFolder
    Dim Item As Object
    Dim Atmt As Attachment
    Dim File As String
    Dim i As Integer
    Set ns = GetNamespace("MAPI")
    Set Inbox = ns.GetDefaultFolder(olFolderInbox)
    Set myfolder = Inbox.Folders("my folder") 'if you want a subfolder of inbox
    i = 0
' Check Inbox for messages and exit of none found
    If myfolder.Items.Count = 0 Then
        MsgBox "There are no messages in the Inbox.", vbInformation, _
               "Nothing Found"
        Exit Sub
    End If
' Check each message for attachments
    For Each Item In myfolder.Items 'change to inbox.items to look in inbox
        strresult = strresult & Item & vbCrLf 'item = subject
        If Item = "A Particular subject" Then
            For Each Atmt In Item.Attachments
                'save the file to a temp location
                    File = "C:\windows\temp\" & Atmt.FileName
                    Atmt.SaveAsFile File
                    i = i + 1
                    '
                    ' here is where you add
                    ' your attachment manipulation
                    ' codes and whatnot
                    '
                    Next Atmt
        Else
        End If
    Next Item
    MsgBox strresult 'if you want to see a popup of the names of the attachments
    End Sub
0
 
m8rixAuthor Commented:
Thanks weellio, but I have already seen that thread when I did a search before posting my question.

I am confident enough to write my own visual basic to do what I require.
Please read my question again and if you think you have an answer, please tell me why my test did not work.

Thanks for your reply
m8rix
0
 
weellioCommented:
sorry was just giving you an alternative way to do things...


your script shoudl work.

have you tried lowering the maco security to see if it makes a difference?
have you run the script manually theough the rules wizard "run now" option?
when you say it "does not work", does it do anything? are there error in event viewer?
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
m8rixAuthor Commented:


> have you tried lowering the maco security to see if it makes a difference?
Yes It is set "Low (Not recommended)"

> have you run the script manually theough the rules wizard "run now" option?
Yes I have but does not work.

> when you say it "does not work", does it do anything? are there error in event viewer?
No error, just the rule does not trigger the code




0
 
m8rixAuthor Commented:
Don't know what it was, but when I removed my conditions on the rule it worked.
I have no idea what it was because my only condition was that the subject contained the word "test"
But when I removed it it worked (triggered on ALL emails) and when I put it back it was working as desired.

Only thing I can think of is that I misspelled the word "test" however that is highly unlikely as I remember that was one of the first things I checked????

thanks for your help anyway, but it seems to have sorted it self out now.

Reg's,
m8
0
 
Vee_ModCommented:
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now