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
Aussie Outlook 365 Rule runs manually but returns the error code "an unexpected error has occurred" when incoming mail arrives Using Outlook 0
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 2
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
A How to stop user form from disapearing once mail window is closed? Outlook VBA and Custom Forms 0
M Outlook, send to > mail recipient - results in plain text email Using Outlook 1
R How to Sync *all* Google Workspace Mail Folders with Outlook 2019 (MS365) Using Outlook 3
S Outlook VBA How to adapt this code for using in a different Mail Inbox Outlook VBA and Custom Forms 0
E Having some trouble with a run-a-script rule (moving mail based on file type) Outlook VBA and Custom Forms 5
S Outlook email to configure setup for each mail Outlook VBA and Custom Forms 1
L Correct E-Mail Pulling Wrong Mail Using Outlook 5
S Outlook mail adressing stops after first match in GAL Using Outlook 0
P Outlook 2013 All imported Mail Rules in error when imported into new profile Using Outlook 5
S Outlook Macro to send auto acknowledge mail only to new mails received to a specific shared inbox Outlook VBA and Custom Forms 0
S Outlook Macro to move reply mail based on the key word in the subjectline Outlook VBA and Custom Forms 0

Similar threads

Top