question

ZanardiMauro-5812 avatar image
0 Votes"
ZanardiMauro-5812 asked JadeLiang-MSFT edited

VBA outlook with contact folder restrict.

Hi,

sorry for my bad english.

In a VBA function for Outlook, I want to look up the address passed to the function in the address book.

If I scan the addresslists, select the addresslist of interest and scan all the contacts, I can find the contact I am looking for (if exist).

This method is fine if I scan my personal address book with few contacts, but in the global address book I have more than 20,000 contacts, a full scan is not possible.

I thought about using the restrict method, but it can only be used on a folder, and I can only find the folder of the personal address book, not for the global address book (first problem).

I applied the restrict method on the personal address book.

I get the contacts I am looking for correctly, and so far so good.

When the search returns a distribution list, I can't see individual members.

I get the number of members that make up the list, but when I go to see its contents I get for each item a string of incomprehensible characters and not an contact object (second problem).

 Function GetAddressList(AddressesToCheck As String) As String 'addressbook As String,
     ' Returns the requested e-mail, taking it from an address book.
        
     Dim AddressesToCheckList As Variant
     Dim ExludedAddressesList() As Variant
     Dim IncludedAddressesList() As Variant
     Dim i As Integer
     Dim j As Integer
     Dim k As Integer
        
     Dim AddressList As Outlook.AddressList
     Dim ItemFiltered As Items
        
     Set AddressList = objNS.Application.Session.AddressLists("Contatti")
    
 ' [ cut code for explode address list into array]
        
     For i = 0 To UBound(IncludedAddressesList)
         Set ItemFiltered = AddressList.GetContactsFolder.Items.Restrict("[FullName] = " & Chr(34) & IncludedAddressesList(i) & Chr(34))
         If ItemFiltered.Count <> 0 Then
             For j = 1 To ItemFiltered.Count
                 If ItemFiltered(j).Class = olDistributionList Then
                     If ItemFiltered(j).MemberCount > 0 Then
                         For k = 0 To ItemFiltered(j).MemberCount - 1
                             Debug.Print "Contact into distribution list: "; ItemFiltered(j).Members(k)
                         Next k
                     End If
                 ElseIf ItemFiltered(j).Class = olContact Then
                     Debug.Print "Contact: "; ItemFiltered(j)
                 Else
                     Debug.Print "Unknow item "; ItemFiltered(j); " - "; ItemFiltered(j).Class
                 End If
             Next j
         End If
     Next i
        
 End Function 'GetAddressList

Thanks for your support.

office-vba-dev
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @ZanardiMauro-5812,

Please kindly understand under Outlook tag, we mainly focus on general issues about Outlook desktop client. Considering that your issue may be more related to VBA development, I would remove office-outlook-itpro tag under your post. Thanks for your understanding and hope your issue would be resolved soon.

1 Vote 1 ·

I can see ItemFiltered(j).Members(k) in IDE inspector, the code return error 450 - Wrong number of arguments or invalid property assignment

0 Votes 0 ·

0 Answers