![]() |
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. |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
![]()
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
|
|||
|
|||
![]()
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
|
|||
|
|||
![]()
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
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
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 |