We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

How to set a rule to run a macro after seeing specific word in the subject Box

LakshmanaRavula
on
Medium Priority
488 Views
Last Modified: 2010-04-08
I'm facing a problem  to set up a rule to run a macro

i've gone to Rule Wizard
 And Started creating a new rule
Checked the Box "with specific words in the Subject" and specified the Specific word

then clicked next

Now I got these options nearer to my task

Start Application
run a script
Perform a cutom action

But from these three I could not mention the macro which I've already created

Can You please help me
Comment
Watch Question

Author

Commented:
Can any body respond immedietly
Karen FalandaysTraining Specialist
CERTIFIED EXPERT

Commented:
Ravula, where is the macro that you have created? Which version of Outlook are you using?
Karen

Author

Commented:
Thank You karen for your immediate response

I'm using Outlook 2002 and I have to run a programme to update my DB based on the mail received. So I have stored a macro in the Tools -  Macro

This Question is in continuation with my previous question posted in

https://www.experts-exchange.com/Applications/MS_Office/Outlook/Q_20945733.html

Thank You

Author

Commented:
Karen,
I'm waiting for your help
Karen FalandaysTraining Specialist
CERTIFIED EXPERT

Commented:
I'm sorry Ravula, I do not do code. Let's see if we can get another expert on board.
Karen

Author

Commented:
can you help me to set a rule to fire a macro in Outlook when it finds a specific word in subject area
CERTIFIED EXPERT
Top Expert 2006

Commented:
I may have fed you some duff info, apologies for that

Ive made a comment in your previous post, if your happy with that then I suggest you close this question

CERTIFIED EXPERT

Commented:
May be can you try this
olInboxItems_ItemAdd will be fired for any incoming mails
The subject is tested against the word you wanted to run your macro


Option Explicit
Dim objNS As NameSpace
Private WithEvents olInboxItems As Items

Private Sub Application_Startup()
  Set objNS = Application.GetNamespace("MAPI")
  Set olInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub Application_Quit()
  Set olInboxItems = Nothing
  Set objNS = Nothing
End Sub

Private Sub olInboxItems_ItemAdd(ByVal Item As Object)


  Dim mySubject as String
  mySubject = "to be fired by the rule" ' MUST be in lowercase as Item.subject will be converted to lcase before comparison

  On Error Resume Next
  If Item.Class = olMail Then
      if len(item.subject) > 0 then
      if instr(1,lcase(item.subject),mySubject,1) <> 0 then
                     'INSERT YOUR CODE HERE
      end if
     end if
  End If
End Sub
Hope this helps
Stefri

Author

Commented:
Stefri My problem is whare to add this code
CERTIFIED EXPERT
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
Stefri Can you make it little Clear

I have pasted this code in TOOLS | Macro | Visual Basic editor (Alt F11)

And I just replaced your " 'INSERT YOUR CODE HERE" with a message box and sent some mails with subject containing "to be fired by the rule"

saved and restarte and tried again But I could not get the message box
CERTIFIED EXPERT

Commented:
What about the Security settings?

Tools/Macro/Security
Set to medium
Close OL

When starting OL, accept the macro to be fired

Stefri
CERTIFIED EXPERT

Commented:
Otherwise, to run a script from the rule wizzard as you planned to do:

replace the code I provided you by
Option Explicit
Sub itemsAdded(Item As Outlook.MailItem) ' THIS IS THE TRICKY PART


  Dim mySubject As String
  mySubject = "to be fired by the rule" ' MUST be in lowercase as Item.subject will be converted to lcase before comparison

  On Error Resume Next
  If Item.Class = olMail Then
      If Len(Item.Subject) > 0 Then
             If InStr(1, LCase(Item.Subject), mySubject, 1) <> 0 Then
                     'INSERT YOUR CODE HERE
             End If
     End If
  End If
End Sub
Stefri
see: http://support.microsoft.com/?kbid=306108 5I had it in French, I hope you'll get it in English

Author

Commented:
Ok Stefri Now I under stood Now it is firing
Thank You

can you participate in my other Question just related to this
CERTIFIED EXPERT

Commented:
Is it working?
If it is using Run a script, I just posted 1 minute ago how to transform the code to be used with Rules Wizzard

Do you want me to put the answer in the alternate thread? If yes, I will jump to postion three for the year in Outlook area

Stefri

Author

Commented:
Yes the code is working and firing the message

And I just replaced your " 'INSERT YOUR CODE HERE" with a message box and sent some mails with subject containing "to be fired by the rule"

And finally as you said I pasted this in On the left pane, double click this OutlookSession

My other Question is

https://www.experts-exchange.com/Applications/MS_Office/Outlook/Q_20945733.html


Please follow and try to help me
Thank You
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.