Aug 5th, 2011, 02:24 AM
#1
Thread Starter
Lively Member
[RESOLVED] Search/Filter through Outlook.AddressEntries
here is my code for getting all the contacts in outlook. My current contact count is 28533. As for now Im using cache to store all the contacts but my boss requires me not to use cache.
Code:
Dim oApp As New Outlook.Application
Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
Dim dt As New DataTable
dt.Columns.Add("id", 0.GetType)
dt.Columns.Add("name", String.Empty.GetType)
dt.Columns.Add("alias", String.Empty.GetType)
dt.Columns.Add("firstname", String.Empty.GetType)
dt.Columns.Add("lastname", String.Empty.GetType)
dt.Columns.Add("contact_no", String.Empty.GetType)
dt.Columns.Add("department", String.Empty.GetType)
dt.Columns.Add("email", String.Empty.GetType)
dt.PrimaryKey = New DataColumn() {dt.Columns("id")}
'oNS.Logon(sUserName, sPassword, False, True)
Dim als As Outlook.AddressLists = oNS.AddressLists
Dim aes As Outlook.AddressEntries = als("Global Address List").AddressEntries()
Dim iAECount As Integer = aes.Count
For i As Integer = 1 To iAECount
Dim ae As Outlook.AddressEntry = aes.Item(i)
If ae IsNot Nothing Then
Dim eu As Outlook.ExchangeUser = ae.GetExchangeUser
If eu IsNot Nothing Then
dt.Rows.Add(New Object() {i, ae.Name, eu.Alias, eu.FirstName, eu.LastName, eu.MobileTelephoneNumber, _
eu.Department, eu.PrimarySmtpAddress})
End If
End If
Next
im a newbie in vb.net field so please always bear with me
Aug 8th, 2011, 01:13 AM
#2
Re: Search/Filter through Outlook.AddressEntries
Hello savior14,
I have read your post, but I don't seem to see any questions in there.
What exactly are you wanting help with?
Also, to be clear, are you creating a Web Application?
Gary
Aug 8th, 2011, 06:46 PM
#3
Thread Starter
Lively Member
Re: Search/Filter through Outlook.AddressEntries
yes its a web application. (sorry for the late response)
as for now, in order to look for a single person, let's say john smith, im looping through a 25k+ records just to look for that record. quite a hassle.
as ive said, my boss also doesn't want me to use cache. is there any .search .filter function to only show a record who has a name 'john' and a surname 'smith' throughout the whole address list?
im a newbie in vb.net field so please always bear with me
Aug 9th, 2011, 12:37 AM
#4
Re: Search/Filter through Outlook.AddressEntries
Hello,
In all honesty, I am not sure.
Although you are creating a Web Application, the specific question you are asking relates to a function within Microsoft Office, specifically Outlook.
As a result, I think this question will be best answered in the Office Development Forum where a lot of clever Office Development guys hang out
Gary
Aug 10th, 2011, 12:48 AM
#5
Thread Starter
Lively Member
Re: Search/Filter through Outlook.AddressEntries
thanks for moving thread.
im a newbie in vb.net field so please always bear with me
Aug 10th, 2011, 01:44 PM
#6
Re: Search/Filter through Outlook.AddressEntries
Have you tried using the .Restrict method of the Items collection?
Or how about the .Find or .Get methods of the Items collection?
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Aug 10th, 2011, 09:27 PM
#7
Thread Starter
Lively Member
Re: Search/Filter through Outlook.AddressEntries
Originally Posted by
RobDog888
Have you tried using the .Restrict method of the Items collection?
Or how about the .Find or .Get methods of the Items collection?
not yet. I'll give it a try and will update you the result.
im a newbie in vb.net field so please always bear with me
Aug 10th, 2011, 09:31 PM
#8
Thread Starter
Lively Member
Re: Search/Filter through Outlook.AddressEntries
checked it but I found no restrict/find/get methods on either Outlook.AddressLists or Outlook.AddressEntries.
im a newbie in vb.net field so please always bear with me
Aug 11th, 2011, 11:12 AM
#9
Re: Search/Filter through Outlook.AddressEntries
Not directly at the parent level but at the Items. Try - aes.Item
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Aug 11th, 2011, 07:18 PM
#10
Thread Starter
Lively Member
Re: Search/Filter through Outlook.AddressEntries
Originally Posted by
RobDog888
Not directly at the parent level but at the Items. Try - aes.Item
no methods/properties found on typing aes.Item unless you specify the index like aes.Item(indexNo) and still no search methods found.
just in case you needed the sample project, please see the attached file.
Attached Files
im a newbie in vb.net field so please always bear with me
Aug 12th, 2011, 01:22 PM
#11
Re: Search/Filter through Outlook.AddressEntries
Ok seems the Address Entries are a different collection.
To start, I optimized your code so it doesnt GetExchangeUser for every single entry as filtered by type
vb Code:
Option Explicit On
Option Strict On
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Outlook.OlAddressEntryUserType
'Add reference to MS Outlook xx.x Object Library
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim oApp As Outlook.Application
Dim aes As Outlook.AddressEntries
Dim ae As Outlook.AddressEntry
Dim eu As Outlook.ExchangeUser
oApp = DirectCast(CreateObject("Outlook.Application"), Outlook.Application)
aes = oApp.GetNamespace("MAPI").AddressLists("Global Address List").AddressEntries
For Each ae In aes
If ae.AddressEntryUserType = olExchangeAgentAddressEntry Or ae.AddressEntryUserType = olExchangeRemoteUserAddressEntry Then
eu = ae.GetExchangeUser
If Not eu Is Nothing Then
Console.WriteLine(ae.Name + ": " + eu.Alias + ", " + eu.FirstName + ", " + eu.LastName + ", " + eu.MobileTelephoneNumber + ", " + eu.Department + ", " + eu.PrimarySmtpAddress)
End If
End If
Next
eu = Nothing
ae = Nothing
aes = Nothing
oApp.Quit()
oApp = Nothing
End Sub
End Class
Last edited by RobDog888; Aug 12th, 2011 at 01:36 PM .
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Aug 12th, 2011, 01:59 PM
#12
Re: Search/Filter through Outlook.AddressEntries
And here is how to directly get the exchange user without looping.
Replace USER NAME with your desired search name.
vb Code:
Option Explicit On
Option Strict On
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Outlook.OlAddressEntryUserType
'Add reference to MS Outlook xx.x Object Library
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim oApp As Outlook.Application
Dim eu As Outlook.ExchangeUser
oApp = DirectCast(CreateObject("Outlook.Application"), Outlook.Application)
eu = oApp.GetNamespace("MAPI").AddressLists("Global Address List").AddressEntries("USER NAME").GetExchangeUser()
If Not eu Is Nothing Then
Console.WriteLine(eu.Name + ": " + eu.Alias + ", " + eu.FirstName + ", " + eu.LastName + ", " + eu.MobileTelephoneNumber + ", " + eu.Department + ", " + eu.PrimarySmtpAddress)
End If
eu = Nothing
oApp.Quit()
oApp = Nothing
End Sub
End Class
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Aug 15th, 2011, 07:12 PM
#13
Thread Starter
Lively Member
Re: Search/Filter through Outlook.AddressEntries
Wow, this is what Ive been searching for! It works like as if you're using the quick search of outlook.
Any way to search like the "Advance Find" of outlook? where you can specify what fields you only wanted to look? (see image attachment below)
Originally Posted by
RobDog888
And here is how to directly get the exchange user without looping.
Replace USER NAME with your desired search name.
vb Code:
Option Explicit On
Option Strict On
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Outlook.OlAddressEntryUserType
'Add reference to MS Outlook xx.x Object Library
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim oApp As Outlook.Application
Dim eu As Outlook.ExchangeUser
oApp = DirectCast(CreateObject("Outlook.Application"), Outlook.Application)
eu = oApp.GetNamespace("MAPI").AddressLists("Global Address List").AddressEntries("USER NAME").GetExchangeUser()
If Not eu Is Nothing Then
Console.WriteLine(eu.Name + ": " + eu.Alias + ", " + eu.FirstName + ", " + eu.LastName + ", " + eu.MobileTelephoneNumber + ", " + eu.Department + ", " + eu.PrimarySmtpAddress)
End If
eu = Nothing
oApp.Quit()
oApp = Nothing
End Sub
End Class
Attached Images
im a newbie in vb.net field so please always bear with me
Aug 16th, 2011, 11:37 AM
#14
Re: Search/Filter through Outlook.AddressEntries
You mean like searching for content in particular areas?
If so take a look at my Search Folder code - http://www.vbforums.com/showthread.php?t=323157
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Aug 16th, 2011, 06:53 PM
#15
Thread Starter
Lively Member
Re: Search/Filter through Outlook.AddressEntries
Originally Posted by
RobDog888
does this work on contacts too?
what I mean in Advance find(outlook >> New E-mail >> To button: >> Advance Find) is something like you're searching in a datatable.
Code:
Dim oApp As New Outlook.Application
Dim eu As Outlook.ExchangeUser
eu = oApp.GetNamespace("MAPI").AddressLists("Global Address List")
.AddressEntries("first_name LIKE '%MyFirstName%' AND email = '
[email protected] ' OR display_name = 'blahblah'")
.GetExchangeUser()
im a newbie in vb.net field so please always bear with me
Aug 17th, 2011, 04:23 PM
#16
Re: Search/Filter through Outlook.AddressEntries
If you get the folderpath to whatever folder you want to search in then it should work.
sScope = "SCOPE ('shallow traversal of " & Chr$(34) & oFolder.Folder.Path & Chr$(34) & "')" ... etc
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Aug 17th, 2011, 06:29 PM
#17
Thread Starter
Lively Member
Re: Search/Filter through Outlook.AddressEntries
it seems complicated to me, I can't understand the code
I'll mark this thread as resolve then if I have spare time, I'll study that search folder thing youve said. Thanks a lot RobDog888.
im a newbie in vb.net field so please always bear with me
Aug 17th, 2011, 07:38 PM
#18
Re: [RESOLVED] Search/Filter through Outlook.AddressEntries
Its not that bad
Just look at the AdvancedSearch method (it actually is the part that calls the search). The arguments are what I had set up and just the sScope argument is a bit but the others are straight forward.
sFilter is the WHERE clause like in SQL.
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Aug 18th, 2011, 09:38 PM
#19
Thread Starter
Lively Member
Re: [RESOLVED] Search/Filter through Outlook.AddressEntries
I don't know if I needed to make a new topic, but here it goes.
vb.net Code:
Private Sub Try4()
On Error Resume Next
Dim oApp As New Outlook.Application
Dim oInbox As Outlook.MAPIFolder = oApp.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
Dim sFolderPath As String = oInbox.FolderPath
'Build a scope string
Dim sScope As String = "SCOPE ('shallow traversal of " & Chr(34) & sFolderPath & Chr(34) & "')"
'Build a filter string (WHERE clause without the WHERE)
Dim sFilter As String = Chr(34) & ("urn:schemas:mailheader:subject") & Chr(34) & " LIKE 'RE:%'"
'Create the Search object by calling AdvancedFind
Dim oSearch As Outlook.Search = oApp.AdvancedSearch(sScope, sFilter, False, "RE Search")
'Save the Search as a Search Folder
Dim oSearchFolder As Outlook.MAPIFolder = oSearch.Save("RE Search")
'MsgBox(oSearchFolder.Items.Count & " Items found!")
'oSearchFolder.Delete
End Sub
I only see my custom made contacts in this folder and not the Global Address List contacts in this code.
vb.net Code:
Dim oInbox As Outlook.MAPIFolder = oApp.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
And about this line, is there any documented guide for the parameters? I don't know if it is used like this for contacts.
vb.net Code:
urn:schemas:contact:detail:email
im a newbie in vb.net field so please always bear with me
Aug 19th, 2011, 12:33 PM
#20
Re: [RESOLVED] Search/Filter through Outlook.AddressEntries
If you specify Contacts then its personal contacts only, not the GAL. If you want the GAL then you need to create a folder object instance referencing that instead.
As for searching in the contacts you would use hte format - "urn:content-classes:person" I believe.
See this link for all the schema breakdowns - http://msdn.microsoft.com/en-us/libr...EXCHG.65).aspx
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Dec 2nd, 2013, 05:29 AM
#21
New Member
Re: [RESOLVED] Search/Filter through Outlook.AddressEntries
Hello everyone,
I have a question - I need to do a similar thing, but on the basis of the email address (i.e. I have a list of email addresses of people from my company and I need to get their display names, job titles and location). I don't know how to retrieve objects on the basis of the email address. I tried modifying the above solutions, but the results are wrong when trying it this way.
Code:
set appOutlook = CreateObject("Outlook.Application")
set objNameSpace = appOutlook.GetNameSpace("MAPI")
set objAddressLists = objNameSpace.AddressLists("Global Address List")
set objAddressEntry = objAddressLists.AddressEntries("[email protected] ").GetExchangeUser()
strFullName = objAddressEntry.Name
strJobTitle = objAddressEntry.JobTitle
strBusinessAddress = objAddressEntry.OfficeLocation
msgBox strFullName & strJobTitle & strBusinessAddress
I am using vbscript. How can I search for object from the Global Address List? From the personal contact list I managed to use
to filter, but I don't know how to implement this here.
Thanks in advance!
Regards
Bartosz
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width