dcsimg
December 8, 2016
Hot Topics:

Making Microsoft Outlook Useful - Part 1

  • November 19, 2002
  • By Sam Huggill
  • Send Email »
  • More Articles »

Hopefully you all use folders within your Outlook environment I must admit that I only recently realised that folders would actually be useful to save my inbox exceeding 100 messages (although it still currently stands at around 500, but thats not the point!)

Along with folders come rules (Tools -> Rules Wizard), which are nifty little things that shift certain emails to certain folders. Very handy.

Anyway, enough of the Outlook basics; lets delve into some programming!

Open up VB, select a new Standard VB Project. Click Project, References and scroll down and check Microsoft Outlook 9 Object Library (or whatever version of Outlook youre running).

To start with, were just going to make a simple project that loads Outlook and reads the folders present. Add the following code to the form:

Private Sub Form_Load()  Dim objOutlook As New Outlook.Application  Dim objNameSpace As Outlook.NameSpace  Dim objInbox As MAPIFolder  Dim objFolder As MAPIFolder      'Get the MAPI reference  Set objNameSpace = objOutlook.GetNamespace("MAPI")    'Pick up the Inbox  Set objInbox = objNameSpace.GetDefaultFolder(olFolderInbox)    'Loop through the folders under the Inbox  For Each objFolder In objInbox.Folders    lstFolders.AddItem objFolder.Name  Next objFolderEnd Sub

You will also need to add a list box, named lstFolders.

Give that a run and hopefully all the folders under your Inbox will appear in the list box.

OK, that was a pretty simple example of how to loop through all the folders under the Inbox and read them. Now well try reading some messages...

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)    'Loop through the items in the Inbox  For Each objMail In objInbox.Items    lstFolders.AddItem objMail.Subject  Next objMailEnd Sub

(Note: If youve got a large number of items in your Inbox like me, you might want to limit the number of messages that the program reads in).

Now that weve read folders and messages, lets take a look at performing some basic messaging tasks...





Page 2 of 3



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel