Record eMail details in Outlook 2007

Status
Not open for further replies.
S

scrawny

Does anyone know how to grab certain information out of an email item

(such as subject, date of receipt, sender etc.).

I can capture this information on Application.NewMail... but to throw

a spanner in the works - I also want the folder name recorded as well

where the user places it.

For example, if a user has Folder 1, Folder 2, Folder 3 under their

Inbox... And as soon as a mail arrives to their inbox they read it and

then decide it needs to go to Folder 2... can I capture the emails

information with the chosen folder at this point?

Cheers,

Scrawny.
 
K

Ken Slovak - [MVP - Outlook]

You can handle the ItemAdd() event on the Items collection of any folders

you want. Get the folder, get its Items collection, then subscribe to the

ItemAdd() event.

"scrawny" <scrawnyguns@gmail.com> wrote in message

news:5cd3581d-01b4-4f61-b921-b8d2d2c42da1@m7g2000prd.googlegroups.com...
> Does anyone know how to grab certain information out of an email item
> (such as subject, date of receipt, sender etc.).
> I can capture this information on Application.NewMail... but to throw
> a spanner in the works - I also want the folder name recorded as well
> where the user places it.

> For example, if a user has Folder 1, Folder 2, Folder 3 under their
> Inbox... And as soon as a mail arrives to their inbox they read it and
> then decide it needs to go to Folder 2... can I capture the emails
> information with the chosen folder at this point?

> Cheers,

> Scrawny.
 
S

scrawny

Thanks for your reply... sorry if I'm a bit slow to catch on, but

where would I be going wrong in the following code:

Dim oApp As New Outlook.Application

Public WithEvents oFolder1 As Outlook.Folder

Public WithEvents oFolder2 As Outlook.Folder

Public WithEvents oFolder3 As Outlook.Folder

Private Sub Application_Startup()

Set oFolder1 = oApp.Session.GetDefaultFolder

(olFolderInbox).Folders.Item("Folder 1")

Set oFolder2 = oApp.Session.GetDefaultFolder

(olFolderInbox).Folders.Item("Folder 2")

Set oFolder3 = oApp.Session.GetDefaultFolder

(olFolderInbox).Folders.Item("Folder 3")

End Sub

Private Sub oFolder1_ItemAdd(ByVal Item As Object)

Dim oMail As Outlook.MailItem

Set oMail = Item

MsgBox oMail.Subject

End Sub

> ... Other Folder objects have the same portion of code as that last

ItemAdd sub.

At the moment I'm just returning the subject to a message box just for

test purposes.

Cheers,

Scrawny
 
K

Ken Slovak - [MVP - Outlook]

What do you mean where are you going wrong, what's not working?

I see 2 things offhand, in Outlook VBA code you never, ever create a new

Outlook.Application object, you use the Application object that's handed to

you and which is trusted. Second, don't assume that what comes to a folder

is necessarily a mail item. It could be a post item, or in Inbox it could be

a task request, meeting request, etc. Use Item.Class to test for olMail to

see if it's really a mail item.

"scrawny" <scrawnyguns@gmail.com> wrote in message

news:620a9295-c407-4269-a369-3384885e28da@v15g2000prn.googlegroups.com...
> Thanks for your reply... sorry if I'm a bit slow to catch on, but
> where would I be going wrong in the following code:

> Dim oApp As New Outlook.Application
> Public WithEvents oFolder1 As Outlook.Folder
> Public WithEvents oFolder2 As Outlook.Folder
> Public WithEvents oFolder3 As Outlook.Folder

> Private Sub Application_Startup()
> Set oFolder1 = oApp.Session.GetDefaultFolder
> (olFolderInbox).Folders.Item("Folder 1")
> Set oFolder2 = oApp.Session.GetDefaultFolder
> (olFolderInbox).Folders.Item("Folder 2")
> Set oFolder3 = oApp.Session.GetDefaultFolder
> (olFolderInbox).Folders.Item("Folder 3")
> End Sub

> Private Sub oFolder1_ItemAdd(ByVal Item As Object)
> Dim oMail As Outlook.MailItem

> Set oMail = Item
> MsgBox oMail.Subject
> End Sub

> ... Other Folder objects have the same portion of code as that last
> ItemAdd sub.

> At the moment I'm just returning the subject to a message box just for
> test purposes.

> Cheers,

> Scrawny
 
S

scrawny

No worries... that makes sense.

But how do I declare the folders which reside under the inbox?

Is that Set command in Application_Startup accurate or is there a

better way.

By the way, I am safely assuming that these folders have already been

set up.

The actual code above does allow the declarations of oFolder1, 2, 3...

but on nothing happens when I add a mail item to the folder. So it's

obviously not declaring the right folder. Or the variable isn't

pointing to the folder that I think it should be.

-Scrawny
 
K

Ken Slovak - [MVP - Outlook]

If the folders don't exist then your return values for Folder1, etc. would

be null (Nothing). So you can test and create the folder if it doesn't

already exist:

Set oFolder1 =

oApp.Session.GetDefaultFolder(olFolderInbox).Folders.Item("Folder 1")

If oFolder1 Is Nothing Then

Set oFolder1 =

oApp.Session.GetDefaultFolder(olFolderInbox).Folders.Add("Folder 1",

olFolderInbox) 'watch for line wrap on this, it's all one line

End If

Step your code and make sure that you get valid Folder objects as the code

runs. You can also check the Items.Count property for each of those folders

to check the number of items in the folder.

Assuming the folders are valid the ItemAdd() event handlers look OK.

"scrawny" <scrawnyguns@gmail.com> wrote in message

news:af0a3a9f-ed41-482f-8933-46e95cbfe97f@y4g2000prf.googlegroups.com...
> No worries... that makes sense.

> But how do I declare the folders which reside under the inbox?
> Is that Set command in Application_Startup accurate or is there a
> better way.
> By the way, I am safely assuming that these folders have already been
> set up.

> The actual code above does allow the declarations of oFolder1, 2, 3...
> but on nothing happens when I add a mail item to the folder. So it's
> obviously not declaring the right folder. Or the variable isn't
> pointing to the folder that I think it should be.

> -Scrawny
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
N linking an already sent/rec'd email to contact record like it did in 2000 Using Outlook 0
S Editing an email with notes and saving it for record using Macro Outlook VBA and Custom Forms 3
A Record opened emails for reopening later Using Outlook 2
A Record opened emails for reopening later Outlook VBA and Custom Forms 16
B Track Record Activity Using Outlook 1
D Record Appointment to Calendar on "Public Folder" Outlook VBA and Custom Forms 13
B Customize contact record phone fields Using Outlook 2
B Macro to record what time it is Outlook VBA and Custom Forms 2
M convert/import a customized record into the default "Account" record BCM (Business Contact Manager) 0
P People/Contact Record gets deleted when I edit it? Using Outlook 3
U No scrolling in note field of contact record Using Outlook 1
R Can BCM monitor and select specific emails and use content info to update the client's record? BCM (Business Contact Manager) 1
M Predefined Outlook Fields not available to add into a BCM record BCM (Business Contact Manager) 0
J How to show the "value" of a user-defined Account field in a Contact Record BCM (Business Contact Manager) 2
J How to create fields that will use the same value on different record types BCM (Business Contact Manager) 2
A delete database --> record remnants ?? BCM (Business Contact Manager) 3
M BCM 2010 Link to Record (very) slow BCM (Business Contact Manager) 2
L Importing multiple record from .vcf (vCard) file Using Outlook 5
P Hyperlink to Access record/Form Outlook VBA and Custom Forms 2
H Re: record of sales for each contact BCM (Business Contact Manager) 1
A Is There An Easier Way to Access a Business Contact Record? BCM (Business Contact Manager) 2
A Programmatically duplicating BCM's "Link to Record" function BCM (Business Contact Manager) 2
C Outlook record the step I take getting to the user template? Outlook VBA and Custom Forms 1
R One Click business contact record creation - From an E Mail? BCM (Business Contact Manager) 1
Y How to record macros in Outlook2007? Outlook VBA and Custom Forms 1
A Links in email getting error message about group policy Using Outlook 4
richardwing Auto forward email that is moves into a specific outlook folder Outlook VBA and Custom Forms 5
J Recommendations for Outlook Duplicate Email Remover Using Outlook 6
Geldner Tweak Junk Email Reporting tool to default to particular email on send? Using Outlook 3
S Outlook 365 Can I change the possible range of highlighting colours when writing an Outlook email? Using Outlook 1
V Can one change the formatting of email title blocks? Using Outlook 0
P default font when sending email from browser Using Outlook 1
D VBA Macro to Print and Save email to network location Outlook VBA and Custom Forms 1
B IMAP server rejects sent email - cannot deliver messages Using Outlook 2
TedSch Small vba to kill political email Outlook VBA and Custom Forms 3
X Open Hyperlinks in an Outlook Email Message (Help with Diane's solution) Outlook VBA and Custom Forms 3
e_a_g_l_e_p_i Email notifications changed with Outlook 2021 Using Outlook 8
glnz How to retrieve or redo Verizon.net email password without affecting Outlook connection? Using Outlook 1
Z Copy specific email body text Outlook VBA and Custom Forms 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
M Outlook 365 refuses to send email Using Outlook 1
B Search and Find Email by Folder Name Outlook VBA and Custom Forms 2
K Closing external IMAP email... Outlook 2013 Using Outlook 0
L Capture email addresses and create a comma separated list Outlook VBA and Custom Forms 5
C Email bomb processing Outlook VBA and Custom Forms 1
O What would be the recommended way to change an email address (family member)? Using Outlook 0
A Outlook 2016 Macro to Reply, ReplyAll, or Forward(but with composing new email) Outlook VBA and Custom Forms 0
L Checking Sender Email Address for trusted domain from list on intranet Outlook VBA and Custom Forms 4
J How do you disable address search box when typing @ in body of email? Using Outlook 0
S HTML Code Embedded in String Within Open Outlook Email Preventing Replace(Application.ActiveInspector.CurrentItem.HTMLBody From Working Outlook VBA and Custom Forms 4

Similar threads

Top