Excel

Open an Outlook Folder

Ease of Use

Intermediate

Version tested with

2000 

Submitted by:

Ivan F Moala

Description:

Opens the specified folder type from Outlook, such as the calendar on inbox. 

Discussion:

You may want to perform a task from Excel, but using one of Outlook's folders. You can access Outlook's folders from Excel using this procedure. Likely, you'll want to combine this procedure with some other task or tasks. 

Code:

instructions for use

			

Option Explicit Enum olFldr olFolderDeletedItems = 3 olFolderOutbox = 4 olFolderSentMail = 5 olFolderInbox = 6 olFolderCalendar = 9 olFolderContacts = 10 olFolderJournal = 11 olFolderNotes = 12 olFolderTasks = 13 olFolderDrafts = 16 olFolderJunk = 23 End Enum Sub OpenOLFolder() Dim MyOutLookApp As Object Dim MyNameSpace As Object Dim MyFolder As Object '// Late Binding Set MyOutLookApp = CreateObject("Outlook.Application") Set MyNameSpace = MyOutLookApp.GetNamespace("MAPI") On Error GoTo ErrFlder 'Change the last "olFolderInbox" to be the folder you actually want to open 'Choose from the list above Set MyFolder = MyNameSpace.GetDefaultFolder(olFldr.olFolderInbox) MyFolder.Display CleanUp: '// Clean-up Set MyFolder = Nothing Set MyNameSpace = Nothing Set MyOutLookApp = Nothing Exit Sub ErrFlder: MsgBox Err.Number & ":" & Err.Description, _ vbMsgBoxHelpButton, "Folder Error", _ Err.HelpFile, Err.HelpContext Resume CleanUp End Sub

How to use:

  1. Copy the code above.
  2. Open your Excel file.
  3. Hit Alt+F11 to open the Visual Basic Editor.
  4. Choose from the menu, Insert-Module.
  5. Paste the code into the right-hand code window.
  6. Close the VBE, saving the Excel file if desired.
 

Test the code:

  1. Go to Tools-Macro-Macros and double-click OpenOLFolder.
 

Sample File:

outlook.zip 7.89KB 

Approved by mdmackillop


This entry has been viewed 226 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express