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