Read Message that triggered Script

  • Thread starter luis_a_roman via OfficeKB.com
  • Start date
L

luis_a_roman via OfficeKB.com

I have a run script in outlook. Want to read the message including the
content for the message that trigger the script. How can I accomplish this?

Guidance and/or sample code will be appreciated.

Luis
 
S

Sue Mosher [MVP]

Are you referring to a "run a script" action attached to an Outlook rule?
The message that triggers the rule is represented by the MailItem argument
for the VBA procedure, e.g.:

Sub RunAScriptRuleRoutine(MyMail As MailItem)
Dim strID As String
Dim olNS As Outlook.NameSpace
Dim msg As Outlook.MailItem

strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set msg = olNS.GetItemFromID(strID)
MsgBox msg.Body

Set msg = Nothing
Set olNS = Nothing
End Sub

For Outlook VBA basics, see http://outlookcode.com/article.aspx?id=49

For another example of a "run a script" rule actions, see:

http://www.outlookcode.com/codedetail.aspx?id=1494

CAUTION: Using this technique has been known to result in corrupt VBA code.
Be sure to export your code modules or back up the VBAProject.otm file.
 
L

luis_a_roman via OfficeKB.com

Yes I'm referring to a "run a script" action. Thank you for sharing. I will
read the article that you refer me to. I'm concerned abut the "CAUTION", does
that means that there is the posibility that the otm file can be corrupted?
If the answer is yes, hopefully in the articles referred to there are best
practices to mitigate that risk.

I need to do some testing but I'm assuming the the code below I can select
the subject and the text and perform some parsing?

What I'm trying to do is to set up a "run script" action for particular
emails with a subject of "Self Portal" and parse it to loaded into an Access
Database. Thank you again for sharing.

Luis
 
S

Sue Mosher [MVP]

Yes, the .otm file can become corrupt. Make sure you have a backup.

The example shows how to access the text in the body of the message. For
other properties, see the object browser -- F2 in VBA.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top