How to Read Email Using VBA

Written by jaime avelar
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Read Email Using VBA
Learn how to read e-mails using VBA. (binary world image by Attila Toro from Fotolia.com)

Knowing how to read e-mail through a Microsoft Access application using Visual Basic for Applications (VBA) can help you make applications more user-friendly. Microsoft Access is a relational database management system often used for small, local databases. Outlook is an e-mail management system included in the Microsoft Office suite. VBA is a computer programming language. In a few steps, you can learn and write VBA code to read Outlook e-mail items.

Skill level:
Easy

Other People Are Reading

Instructions

  1. 1

    Open Microsoft Access 2007. Click "Database Tools" and select "Visual Basic." Select the "Tools" menu and click "References." Check the box next to "Microsoft Outlook (version number) Object Library." Click "OK."

  2. 2

    Copy and paste the code below into your new module. The code will read the "Inbox" folder in Microsoft Outlook e-mail and display the subject and body through a message box.

    Private Sub ReadOutlookMail()

    Set otlkApp = CreateObject("Outlook.Application")

    Set MAPISpace = otlkApp.GetNamespace("MAPI")

    Set otlkFolder = MAPISpace.GetDefaultFolder(olFolderInbox)

    For Each MailItem In otlkFolder.Items

    MsgBox "Subject:" & MailItem.Subject & "Body:" & MailItem.body
    

    Next MailItem

    End Sub

  3. 3

    Press "F5" to run your "ReadOutlookMail" subroutine.

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.