• Subject: Re: Look for patterns in Recipient Address
  • Author: Sue Mosher [MVP]
  • Date: 18 Jan 2010
  • References: 1 2
Use the Instr() function to search for substrings; look it up in Help. Or, learn how to use regular expressions to do pattern matching. See http://www.outlookcode.com/article.aspx?ID=41 for links to RexEx resources. And there's nothing weird about the recipient address. If you're in an Exchange organization, it's perfectly normal to have a long address in X.400 format.
Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54
<Axel Gehrke> wrote in message news:2010118155419axel.gehrke@bshg.com...
> Sue, my MVP :-) > Thanks so much, also for clearing up the code. All suggested changes work. > That happens, if you copy and paste from different sources without totally > understanding what you are doing. > > myRecipient.Address gives a weird statement for company internal > recipients, myRecipient.name works better. To keep the code short it would > help greatly to search for certain patterns (department abbreviations e.g. > ENG for engineering). > > If item.Name ?contains? "ENG" Then > Set myPSTSentTemp = myPSTSent.Folders("ENG") > Set item.SaveSentMessageFolder = myPSTSentTemp > End If > > Axel > > > > Sue Mosher [MVP] wrote: > > A glance at the object browser (F2 in Outlook VBA) would show you that > thereis > 18-Jan-10 > > A glance at the object browser (F2 in Outlook VBA) would show you that > there > is no MailItem.Recipient object, as you have in this statement: > > myRecipient = itemMail.Recipient > > Instead, there is a Recipients collection, which you can iterate with a > For > Each ... Next loop to get information about each Recipient in turn: > > For Each myRecipient in itemMail.Recipients > MsgBox myRecipient.Address > ' etc. > Net > > I see lots of other problems with your code: > > 1) This statement should never appear in Outlook VBA code: > > Set myOlApp = CreateObject("Outlook.Application") > > Instead use the intrinsic Application object that VBA exposes: > > Set myOlApp = Application > > 2) Only one Namespace is active per Outloook session, so you do not need > two > separate variables. Replace these statements > > Set myNamespace = myOlApp.GetNamespace("MAPI") > Set myPSTspace = myOlApp.GetNamespace("MAPI") > > with > > Set myNamespace = myOlApp.Session > > 3) This statement is not the correct way to work with the item being sent: > > Set itemMail = myOlApp.ActiveInspector.CurrentItem > > Instead, use the Item object passed by the ItemSend event handler's > procedure signature > > Set itemMail = Item > > Or, better, omit that statement and just replace itemMail with Item > everywhere in your code. > > 4) You do not need a statement like this to resend the item you just sent; > delete this statement: > > itemMail.Send > > -- > Sue Mosher, Outlook MVP > Author of Microsoft Outlook 2007 Programming: > Jumpstart for Power Users and Administrators > http://www.outlookcode.com/article.aspx?id=54 > > Previous Posts In This Thread: > > > Submitted via EggHeadCafe - Software Developer Portal of Choice > Spambot Killer ASP.NET Mailto: Hyperlink Control > http://www.eggheadcafe.com/tutorials/aspnet/9817ba6f-ba00-4523-9097-f0235cdcb480/spambot-killer-aspnet-ma.aspx
18 Jan 2010How to read RECIPIENT and set SaveSentMessageFolder accordingly.Axel Gehrke
18 Jan 2010\ Re: How to read RECIPIENT and set SaveSentMessageFolder accordingly.Sue Mosher [MVP]
18 Jan 2010   \ Look for patterns in Recipient Address.Axel Gehrke
18 Jan 2010      \ Re: Look for patterns in Recipient Address.Sue Mosher [MVP]
Contact Us
All times are in (US) Eastern Daylight Time (GMT -4:00)