Run-time error 287: Excel VBA Referencing Outlook Objects

dhancy

Board Regular
Joined
Jul 10, 2013
Messages
100
Hello,

As I continue my studies into how to navigate the Outlook hierarchy using Excel VBA, I find that I often run into Run-time error '287':

Please forgive me for asking another question on this subject.

First, my understanding of the Outlook hierarchy is this:

Outlook Application
- Namespace
--- Address Lists
----- Address List
------- Address Entries
--------- Address Entry

If this is not correct, let me know as this might be the source of all my 287 errors.

Here is a snippet of my code:

VBA Code:
Dim olApp As Outlook.Application
Dim olNS As Outlook.Namespace
Dim olAddLists As Outlook.AddressLists
Dim olGAL As Outlook.AddressList
Dim olEntries As Outlook.AddressEntries
Dim olEntry As Outlook.AddressEntry

Set olApp = Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
Set olAddLists = olNS.AddressLists

For Each olGAL In olAddLists
   Set olEntries = olGAL.AddressEntries
   For Each olEntry In olEntries
      …
   Next
Next

The 287 error comes on the "Set olEntries" line.

I have Windows 10 and Office 2016.

Tools/References include:
- Visual Basic for Applications
- Microsoft Excel 16.0 Object Library
- OLE Automation
- Microsoft Office 16.0 Office Library
- Microsoft Outlook 16.0 Object Library


Any idea of what I am doing wrong here?


Thanks again.


Dennis
 

Some videos you may like

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Watch MrExcel Video

Forum statistics

Threads
1,113,836
Messages
5,544,596
Members
410,624
Latest member
smartsanjiv64
Top