run VBA code from a rule

  • Thread starter Thread starter Daniel Rimmelzwaan
  • Start date Start date
D

Daniel Rimmelzwaan

We have a problem with outlook integration in an ERP system. The system
basically runs a service that polls an outlook folder. When an email is
received, it logs the email internally and moves the email to a user defined
outlook folder. All the email address fields in this system are 80
characters long, and when it receives an email with a from address longer
than 80 characters, we're in trouble. Rather than handle exceptions
properly, the system doesn't know what to do and tries it again, ad
infinitum. After a while, it shuts down the email logging feature altogether
and someone has to go in, remove the culprit email, and start the service
back up again.

I tried to see if I can create a rule that moves emails with a from address
longer than 80 characters to a Review folder, but that does not seem to be
available. So, I guess the next step is to create a VBA routine that checks
the length of the from address and moves the email to a non-polling folder.

My question is two-fold:
1: Can I run a macro or something from a rule, or any other VBA program? I
saw where it says 'Run a script', but that does not display my macro for
selection. I need to know how to make my script/macro/module show up in that
selection screen.
2: Could anyone give me a code sample of how to do this?

Thanks for your time,
Daniel
 
This works only in Outlook 2002 and 2003. You macro needs to be a public Sub
with a MailItem argument:

Public Sub MyMacro(ThisMsg as MailItem)
' your code to handle ThisMsg goes here
End Sub
 
Thank you Sue, I can see my macro in the script list now.

I used the following code to see if I can even access the email address:

Public Sub MyNewSub(ThisMsg As MailItem)
MsgBox ("Email: " & ThisMsg.SenderEmailAddress)
End Sub

When I send an email to myself, first outlook asks me to grant access to my
address book, and then it displays something like:

/O=ACME/OU=DOMAIN/CN=RECIPIENTS/CN=DRIMMELZWAAN

I do NOT want it to look in my addressbook, simply show the email address
that is in the From box, so in this example that would be
(e-mail address removed), so I can test the number of characters.
However, SenderEmailAddress is the only property that I could find that
would match my need, and obviously I can't get that to work.

Any tips on how to do this would be very helpful.

Thanks,
Daniel.
 
See http://www.outlookcode.com/d/sec.htm for your options with regard to the
"object model guard" security prompts related to accessing address-related
fields in Outlook 2000 SP2 and later versions. I recommend that you use the
Redemption library from http://www.dimastr.com/redemption/, since that will
also let you access the SMTP address, as shown in the sample at
http://www.outlookcode.com/d/code/getsenderaddy.htm#redemption

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Back
Top