I am trying to access the AddressEntries property of an AddressList inside a VBA script within Excel. The list is a Global Address List containing contacts stored on an Exchange Server.
When I try to run the following code though, it gives me an error:
Run-time error '287': Application-defined or object-defined error
Here is the barebones code I'm trying to execute. The debugger stops on the line where I try to access the AddressEntries.
Public Sub Test()
Dim appOL As Object
Dim mapiNamespace As Object
Dim GAL As AddressList, allGAL As AddressEntries
Set appOL = GetObject(, "Outlook.Application")
Set mapiNamespace = appOL.GetNamespace("mapi")
Set GAL = mapiNamespace.AddressLists("Global Address List")
Set allGAL = GAL.AddressEntries 'Debugger stops here
MsgBox allGAL.Count
End Sub
Would some setting on the server be able to prevent my access to the entries of the list? Is there some other way to get the entries? My end goal is to get the entries from the list that correspond to a list of email addresses I have in an excel file and check whether each entry has a work phone # listed in its Phone Number property.
Edit: Image of Outlook graying out my options
Set app
Edit2: This still gives me the same error on the second line
Set appOL = CreateObject("Outlook.Application")
Set oGAL = appOL.GetNamespace("MAPI").AddressLists("Global Address List").AddressEntries