Capture Inbound E-mail Subject with VBA

  • Thread starter Thread starter Brad
  • Start date Start date
B

Brad

I am just starting to experiment with Outlook VBA.

I am looking for a simple example of how to capture the content of an
inbound e-mail’s subject so that I can see it in VBA code.

For my first step, I would simply like to be able to do a MSGBOX to display
the captured Subject.

Thanks for your help,

Brad
 
What is an 'inbound e-mail's subject'?

This prompts the subject of the first selected item in the current folder:

Dim Sel as Outlook.Selection
Set Sel=Application.ActiveExplorer.Selection
If Sel.Count>0 Then Msgbox Sel(1).Subject

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool
: VBOffice Reporter for Data Analysis & Reporting
: <http://www.vboffice.net/product.html?pub=6&lang=en>


Am Wed, 2 Sep 2009 20:08:01 -0700 schrieb Brad:
 
Michael,

Sorry, I didn’t explain very clearly what I am trying to do.

I have set up a little VBA module that is initiated by Outlook each time a
new e-mail arrives. It simply displays a message that control was passed to
it. This works nicely

I am now trying to capture the subject line of each e-mail and do something
with it in the VBA code.

Being new to Outlook VBA, I would like to see an example of how to get at
the subject line of each e-mail in VBA as they arrive.

Thanks for your help.

Brad
 
For instance, see the ItemAdd event of the Inbox folder. There's an example
in the VBA help file.

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool
: VBOffice Reporter for Data Analysis & Reporting
: <http://www.vboffice.net/product.html?pub=6&lang=en>


Am Thu, 3 Sep 2009 05:21:01 -0700 schrieb Brad:
 
Michael,

Sorry, I didn’t explain very clearly what I am trying to do.

I have set up a little VBA module that is initiated by Outlook each time a
new e-mail arrives. It simply displays a message that control was passed to
it. This works nicely

I am now trying to capture the subject line of each e-mail and do something
with it in the VBA code.


Try this:

Sub IncomingMailHandler(ThisMail as MailItem)
MsgBox ThisMail.Subject
End Sub


To "install" the script, create a new "run script" rule for incoming
messages in Tools / Rules and Alerts (if that isn't how you already did
it).
 
Back
Top