Making Microsoft Outlook Useful - Part 1
So you think youre ready to play around with messages eh? Well, true, you probably are. Messages are referred to as items in Outlook, as you can also have appointments & notes etc. For now, well be dealing with the items located within the Inbox folder.
The next snippet of code shows you how to simple create a message, write a short message, and save it in the Drafts folder:
Private Sub Form_Load() Dim objOutlook As New Outlook.Application Dim objNameSpace As Outlook.NameSpace Dim objInbox As MAPIFolder Dim objMail As MailItem 'Get the MAPI reference Set objNameSpace = objOutlook.GetNamespace("MAPI") 'Pick up the Inbox Set objInbox = objNameSpace.GetDefaultFolder(olFolderInbox) Set objMail = objInbox.Items.Add With objMail .Subject = "Well done" .Body = "This article is great!" .To = "firstname.lastname@example.org" .Save End WithEnd Sub
If you look closely at the code youll see that Ive been rather cheeky with the body and subject lines, so to get your own back you can run the next piece of code to delete my ego booster!
Private Sub Form_Load() Dim objOutlook As New Outlook.Application Dim objNameSpace As Outlook.NameSpace Dim objDrafts As MAPIFolder Dim objMail As MailItem 'Get the MAPI reference Set objNameSpace = objOutlook.GetNamespace("MAPI") 'Pick up the Drafts folder Set objDrafts = objNameSpace.GetDefaultFolder(olFolderDrafts) Set objMail = objDrafts.Items("Well done") objMail.DeleteEnd Sub
Right, thats just about it for the first part in this series! In part 2 youll learn how to:
- Filter emails as you read them in through different criteria
- Build a program which allows you to:
- Read in messages from a folder
- Filter duplicates & blanks
- Apply a date criteria
- Locate the email details
- Write them to a file
See you again soon for some more exciting Outlook programming!
Page 3 of 3