I want all(FirstName LastName) from global address book in a listview :
Firstname LastName
anyone has the solution?
Printable View
I want all(FirstName LastName) from global address book in a listview :
Firstname LastName
anyone has the solution?
Try this...VB Code:
Private olApp As Outlook.Application Private olNS As Outlook.NameSpace Private olAL As Outlook.AddressList Private olAE As Outlook.AddressEntry Private Sub Form_Load() Dim Counter As Long Set olApp = New Outlook.Application Set olNS = olApp.GetNamespace("MAPI") For Each olAL In olNS.AddressLists For Each olAE In olAL.AddressEntries DoEvents Counter = Counter + 1 Label1.Caption = Counter ListView1.ListItems.Add , , olAE.Name ListView1.ListItems(ListView1.ListItems.Count).SubItems(1) = olAE.Address Next Next End Sub
Getting error on this line:
Run-time error-380Code:ListView1.listitems(ListView1.listitems.Count).SubItems(1) = olAE.Address
Invalid property value
Code is getting values(Checked with f8)
Also this code is giving the alias of the member.
I need FirstName and LastName
Note, the AddressEntries is for your local AddressBook and not the Global Address List from Exchange. In my signature GAL example I use CDO 1.21 to retrieve the First and Last names in it and populate a listview.
Did you add the reference to CDO 1.21?
Not in above code.
But for your code i have included ref to cdo 1.21.
I got following error :
Run-time error'2147219963(80040605)
Collaboration Data Objects-[MAP_E_Not_INITIALIZED(80040605)]]
What i have to do if i want only firstname and lastname in a listview?
I am trying to run your code.
I have added ref to cdo 1.21, outlook 11.0
I am using xp(outlook 2003)
Application hangs up at this line :
I dont understand why your code is not running on my computer...Code:Set oAEntries = moCDO.AddressLists.item("Global Address List").AddressEntries
For i = 1 To oAEntries.Count
Help me out...
You need to be running Outlook in an Exchange environment and have permissions to view the GAL.
I am able to get all the details of GAL in my outlook. I have this code(not mine) which takes display Firstname and lastname from GAL.
So i dont think there is any problem with my exchnage server or Anything....Code:Private olApp As Outlook.Application
Private olNS As Outlook.NameSpace
Private olAL As Outlook.AddressList
Private olAE As Outlook.AddressEntry
Dim sName As String
Dim arrName() As String
Private Sub Command1_Click()
On Error Resume Next
'Private Sub UserControl_Initialize()
Dim Counter As Long
Dim listitems As ListItem
Set olApp = New Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
For Each olAL In olNS.AddressLists
For Each olAE In olAL.AddressEntries
DoEvents
sName = olAE.Name
SplitName
Set listitems = ListView1.listitems.Add
listitems.Text = arrName(0) 'First name
listitems.SubItems(1) = arrName(1) 'Last name
Next
Next
End Sub
Private Sub Form_Load()
ListView1.View = lvwReport
ListView1.ColumnHeaders.Add , , "First Name", 1500
ListView1.ColumnHeaders.Add , , "Last Name", 1500
End Sub
Private Sub SplitName()
'Split the name to first and last
'--------------------------------
arrName() = Split(sName, " ")
End Sub
Robdog can u tell me on which platform u r code is running....
I AM WORKING ON WINDOWS XP(OFFICE 2003), EXCHAANGE SERVER 2003.
Should your code run on my comp?
Hello Sir !
I have made certain changes in ur code and able to run it.
Now i am getting the details in a listview.Code:Dim oAEntries As AddressEntries
Dim oAEntry As AddressEntry
Dim oFields As Field
I am trying to take only Lastname,FirstName(In single column) in a listview or(it can be listbox also) and emailaddress as hidden field because i want email address of the seleted person. I am trying to write code for this with the help of your code but not getting the desired output...
Can u guide me on this issue....
Thanks...
Hello !
Its getting really difficult for me to get this....
I am able to get firstname and lastname of all the contacts in a listbox.Code:Dim objoutlk As New Outlook.Application
Dim fol As Outlook.mapiFolder
Dim mapises As MAPI.Session
Dim contact As Outlook.ContactItem
Dim ns As Outlook.NameSpace
Dim var1 As String
Private Const cdoPR_GIVEN_NAME As Long = &H3A06001E
Private Const cdoPR_SURNAME As Long = &H3A11001E
Private Const cdoPR_EMAIL As Long = &H39FE001E
Private Sub Form_Load()
Set ns = objoutlk.GetNamespace("MApi")
Set fol = ns.GetDefaultFolder(olFolderContacts)
Me.Show
For Each contact In fol.Items
List1.AddItem contact.FirstName & " , " & contact.LastName
Next
Set mapises = CreateObject("MAPI.session")
mapises.Logon "", "", False, False
gal
Set ns = Nothing
Set objoutlk = Nothing
Set fol = Nothing
End Sub
Public Sub gal()
Dim oAEntries As AddressEntries
Dim oAEntry As AddressEntry
Dim oFields As Field
Dim i As Integer
Dim ii As Integer
Dim iii As Integer
Dim vDetails As Variant
On Error GoTo errorfun
Set oAEntries = mapises.AddressLists.Item("Global Address List").AddressEntries
For i = 1 To oAEntries.Count
Set oAEntry = oAEntries.Item(i)
var1 = ""
For ii = 1 To oAEntry.Fields.Count
Set oFields = oAEntry.Fields(ii)
vDetails = oFields.Value
If oFields.ID = cdoPR_SURNAME Then
var1 = var1 & vDetails & " , "
ElseIf oFields.ID = cdoPR_GIVEN_NAME Then
var1 = var1 & vDetails
MsgBox var1
List1.AddItem var1
End If
Next
Next
errorfun:
gal
End Sub
I want email ids of all of them.
I am taking lastname,firstname in one column... Is there any way i can get emailid of all these in second column(which will be hidden).
If you look at my code example in my signature it shows how to get the email address too.