A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Problem with macro running from rule



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old September 4th 08, 12:21 PM posted to microsoft.public.outlook.program_addins
Teki
external usenet poster
 
Posts: 1
Default Problem with macro running from rule

I use outlook 2003 with exchange server. When I receive mail from specific
email address I want to move it to specific folder based on string in subject
and than pare the subject of mail and create new user property with value
parsed from subject.
Now I have macro that is capable of parsing the subject and adding parsed
value to new user property and outlook rule that moves mail based on address
and subject.

Problem is that macro works fine and rule works fine, but together they
don't work correct.
It seems that when mail is received macro creates user property correctly,
but than mail is moved and the value in user property is lost (maybe because
of connection with exchange?). If I create separate rules - one that executes
macro and other that moves mail they work fine if I execute each one
individually (by hand). If they are executed automaticaly, when mail is
received user property is gone. (I've tried different combinations.. e.g.
rule 1 than rule 2, rule 2 than rule 1). It just wont work.

Any help would be appreciated.

Here is my macro code:
Sub Jira(MyMail As Outlook.MailItem)
Dim strID As String
Dim Item As Outlook.MailItem
Dim olNS As Outlook.NameSpace

strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set Item = olNS.GetItemFromID(strID)

mailSubject = Item.Subject

posStart = InStr(mailSubject, "(")

posEnd = InStr(mailSubject, ")")

jiraIDLen = posEnd - posStart

jiraId = Mid(mailSubject, posStart + 1, jiraIDLen - 1)

Dim prop As Outlook.UserProperty

Set prop = Item.UserProperties.Find("JiraID")

If TypeName(prop) = "Nothing" Then
Set prop = Item.UserProperties.Add("JiraID", olText, True)
prop.Value = jiraId

Item.Save
End If

End Sub

Thnx.

  #2  
Old September 4th 08, 01:49 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Problem with macro running from rule

Why are you instantiating Item when you're being passed a perfectly good
MyMail object? Try working only on MyMail and see what happens. I'd also
have the macro code do the moving and remove that from the rule.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Teki" wrote in message
...
I use outlook 2003 with exchange server. When I receive mail from specific
email address I want to move it to specific folder based on string in
subject
and than pare the subject of mail and create new user property with value
parsed from subject.
Now I have macro that is capable of parsing the subject and adding parsed
value to new user property and outlook rule that moves mail based on
address
and subject.

Problem is that macro works fine and rule works fine, but together they
don't work correct.
It seems that when mail is received macro creates user property correctly,
but than mail is moved and the value in user property is lost (maybe
because
of connection with exchange?). If I create separate rules - one that
executes
macro and other that moves mail they work fine if I execute each one
individually (by hand). If they are executed automaticaly, when mail is
received user property is gone. (I've tried different combinations.. e.g.
rule 1 than rule 2, rule 2 than rule 1). It just wont work.

Any help would be appreciated.

Here is my macro code:
Sub Jira(MyMail As Outlook.MailItem)
Dim strID As String
Dim Item As Outlook.MailItem
Dim olNS As Outlook.NameSpace

strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set Item = olNS.GetItemFromID(strID)

mailSubject = Item.Subject

posStart = InStr(mailSubject, "(")

posEnd = InStr(mailSubject, ")")

jiraIDLen = posEnd - posStart

jiraId = Mid(mailSubject, posStart + 1, jiraIDLen - 1)

Dim prop As Outlook.UserProperty

Set prop = Item.UserProperties.Find("JiraID")

If TypeName(prop) = "Nothing" Then
Set prop = Item.UserProperties.Add("JiraID", olText, True)
prop.Value = jiraId

Item.Save
End If

End Sub

Thnx.


  #3  
Old September 4th 08, 02:07 PM posted to microsoft.public.outlook.program_addins
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Problem with macro running from rule

Why are you instantiating Item when you're being passed a perfectly good
MyMail object?


I recognize this as probably derived from some of my code. MyMail is not
trusted by the "object model guard." Therefore, Item is instantiated using
GetItemFromID and MyMail.EntryID, so that Item *is* a trusted object. That's
not terribly relevant for this particular scenario, which doesn't use any
blocked properties or methods, but it's definitely a general model for a "run
a script" rule.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx



"Ken Slovak - [MVP - Outlook]" wrote:

Why are you instantiating Item when you're being passed a perfectly good
MyMail object?

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Teki" wrote in message
...

Here is my macro code:
Sub Jira(MyMail As Outlook.MailItem)
Dim strID As String
Dim Item As Outlook.MailItem
Dim olNS As Outlook.NameSpace

strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set Item = olNS.GetItemFromID(strID)

mailSubject = Item.Subject


  #4  
Old September 4th 08, 02:09 PM posted to microsoft.public.outlook.program_addins
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Problem with macro running from rule

What symptoms suggest that "the value in user property is lost" when the item
is moved? Where is it being moved to?
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Teki" wrote:

I use outlook 2003 with exchange server. When I receive mail from specific
email address I want to move it to specific folder based on string in subject
and than pare the subject of mail and create new user property with value
parsed from subject.
Now I have macro that is capable of parsing the subject and adding parsed
value to new user property and outlook rule that moves mail based on address
and subject.

Problem is that macro works fine and rule works fine, but together they
don't work correct.
It seems that when mail is received macro creates user property correctly,
but than mail is moved and the value in user property is lost (maybe because
of connection with exchange?). If I create separate rules - one that executes
macro and other that moves mail they work fine if I execute each one
individually (by hand). If they are executed automaticaly, when mail is
received user property is gone. (I've tried different combinations.. e.g.
rule 1 than rule 2, rule 2 than rule 1). It just wont work.

Any help would be appreciated.

Here is my macro code:
Sub Jira(MyMail As Outlook.MailItem)
Dim strID As String
Dim Item As Outlook.MailItem
Dim olNS As Outlook.NameSpace

strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set Item = olNS.GetItemFromID(strID)

mailSubject = Item.Subject

posStart = InStr(mailSubject, "(")

posEnd = InStr(mailSubject, ")")

jiraIDLen = posEnd - posStart

jiraId = Mid(mailSubject, posStart + 1, jiraIDLen - 1)

Dim prop As Outlook.UserProperty

Set prop = Item.UserProperties.Find("JiraID")

If TypeName(prop) = "Nothing" Then
Set prop = Item.UserProperties.Add("JiraID", olText, True)
prop.Value = jiraId

Item.Save
End If

End Sub

Thnx.

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to setup a rule to forward rule in Outlook (xp or 2003) to forward emails from a certain domain when app isnt running? KingCronos Outlook - General Queries 7 November 15th 06 11:22 AM
Problem running a VBA script from an Outlook rule Olivier Langlois Outlook and VBA 5 March 16th 06 09:03 PM
Problem running a VBA script from an Outlook rule Olivier Langlois Add-ins for Outlook 5 March 16th 06 09:03 PM
Running Macro Sanjeev kumar Kodavalla Outlook - Using Forms 2 March 5th 06 07:24 PM
Running a macro SuperSlueth Outlook - Using Forms 15 February 7th 06 09:51 PM


All times are GMT +1. The time now is 06:40 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.