Capture Inbound E-mail Subject with VBA

Status
Not open for further replies.
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
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
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

Am Wed, 2 Sep 2009 20:08:01 -0700 schrieb 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
 
B

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

"Michael Bauer " wrote:



> 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

> > >

> Am Wed, 2 Sep 2009 20:08:01 -0700 schrieb 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

>
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
For instance, see the ItemAdd event of the Inbox folder. There's an example

in the VBA help file.

Best regards

Michael Bauer

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.

> 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

> "Michael Bauer " wrote:
>
>

>
>> 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
>

>> >> >>

>

>
>> Am Wed, 2 Sep 2009 20:08:01 -0700 schrieb 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

> >
 
L

Luc

On Thu, 3 Sep 2009 05:21:01 -0700, Brad <Brad
wrote:


> 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).
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
L Capture email addresses and create a comma separated list Outlook VBA and Custom Forms 5
R Capture Sender's Display name and Address Outlook VBA and Custom Forms 3
M Using field names to capture a data element Using Outlook 0
I Capture incoming emails Outlook VBA and Custom Forms 1
A Capture network traffic in IE to file Outlook VBA and Custom Forms 5
JorgeDario How to capture and save the text, when responding a MailItem? Outlook VBA and Custom Forms 3
G Capture "forward event" ? Outlook VBA and Custom Forms 11
J VBA Form in Outlook to capture data and complile a mail Outlook VBA and Custom Forms 2
A how to capture events for next item Outlook VBA and Custom Forms 10
R How to capture a Mailitem Event Outlook VBA and Custom Forms 3
A how to capture outlook 2007 events Outlook VBA and Custom Forms 4
T Some way to capture who marks an email as read Outlook VBA and Custom Forms 1
C Event Capture - Item Context Menu (Delete). Can you hook it? Outlook VBA and Custom Forms 1
Steven 2007 New PC vs Old PC - Micro Font on Inbound Emails :( Using Outlook 4
S How can I create a rule to move inbound emails from any of my contacts out of Inbox? Using Outlook 1
Sarge USMC Outlook 13 not displaying POP inbound emails Using Outlook 12
J Edge + TMG 2010 No email inbound/outbound and cannot telnet to port 25 on TMG Exchange Server Administration 0
S Hub transport ex2007 - monitoring inbound Exchange Server Administration 2
S Inbound email filtering beyond Rules Using Outlook 7
B Initiate VBA as a result of inbound e-mail? Outlook VBA and Custom Forms 1
L Help: set flag for sent mail to check if received an answer Outlook VBA and Custom Forms 2
A Macro Mail Alert Using Outlook 4
e_a_g_l_e_p_i MY Outlook 2021 changed the format of the shortcuts for mail, calendar etc. Using Outlook 10
Z Outlook 365 Automatically assign categories to incoming mail in a shared folder Round Robin Outlook VBA and Custom Forms 1
W Outlook 365 I am getting the "Either there is no default mail client" error when I try to send an email on excel Office 365 Using Outlook 1
D Gmail mail is being delivered to a different email inbox in Outlook App 2021 Using Outlook 2
P What is your strategy for dealing with SPAM and Junk Mail? Using Outlook 1
C Code to move mail with certain attachment name? Does Not work Outlook VBA and Custom Forms 3
T 1:1 Datatransfer from incoming mail body to customs form body Outlook VBA and Custom Forms 0
O Mail rule issue Using Outlook 3
A manual rule sends mail to wrong folder Using Outlook 5
Aussie Outlook 365 Rule runs manually but returns the error code "an unexpected error has occurred" when incoming mail arrives Using Outlook 1
D ISOmacro to extract active mail senders name and email, CC, Subject line, and filename of attachments and import them into premade excel spread sheet Outlook VBA and Custom Forms 2
Witzker Outlook 2019 Macro to answer a mail with attachments Outlook VBA and Custom Forms 2
D Outlook 2003 Mail Fails Using Outlook 1
Cathy Rhone Mail merge error message Using Outlook 1
R Sent emails show iCloud mail account not the alias Using Outlook 2
D Advanced e-Mail search on from/to contact group only searches for first 20 contacts in group Using Outlook 0
P Print attachments automatically and move the mail to an existing folder called "Ted" Outlook VBA and Custom Forms 4
P Importing other e-mail accounts into Outlook Using Outlook 1
lcarpay Stay in the mail folder pane after ctrl-1 Using Outlook 1
O Exchange Sync period only (e.g. last years mail) Using Outlook 0
F Excel VBA to move mails for outlook 365 on secondary mail account Outlook VBA and Custom Forms 1
M Convertor for Outlook Express Mail Store (.dbx) to Outlook Mail Store (.pst) Using Outlook 0
T vba extract data from msg file as attachment file of mail message Outlook VBA and Custom Forms 1
J E-mail held in Outbox while Minimized Using Outlook 3
G Forward email body to other mail list directly from Exchange server Exchange Server Administration 1
T Outlook creates a copie of every mail I send Using Outlook.com accounts in Outlook 4
N Please advise code received new mail Using Outlook 0
M Outlook 2010 How could I globally redesign an outlook template form/region/inspector template used to display mail lists or an individual mails? Outlook VBA and Custom Forms 0

Similar threads

Top