0
votes

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
1
Did Outlook prompt for access while you run the code? Chances are Outlook is preventing "programmatic access" thus giving you the error. Here is an article on enabling access that you can try out. - Alex
Did you look at this answer? It seems to show it a bit differently. - PeterT
@Alex it seems like you're onto something there. My administrator seems to have grayed out options to mess with the programmatic access (see edit & image in question above) - takanuva15
@PeterT I tried the code in your link (see edit to question) but the same error is happening on the 2nd line. I am able to retrieve the Global Address List, but I get an error immediately when I put put in the ".AddressEntries" stuff as well - takanuva15
@Alex Ok cool. If you post your comment as an answer, I will upvote it and mark it with a green check - takanuva15

1 Answers

2
votes

It seems like your antivirus treating the access as potential threat - it's a coded automation for accessing your data afterall.

Check with your admin and see if you can enable one of the options shown in your trust center (Open Outlook 2010, go to "File/Options/Trust Center" menu item, and then click on the "Trust Center Settings" button at the right side of the dialog box), preferably the very first one.

Here is an article on enabling access that you can try out.