Hi,can some one show me an example of extracting the outlook contacts to a listbox?,would be good just with pure api so no dlls etc thanks
Printable View
Hi,can some one show me an example of extracting the outlook contacts to a listbox?,would be good just with pure api so no dlls etc thanks
API's are using dll's. Try using VBScript in VB. Google this for some excellent code "VBScript Outlook" without the quotes.
Hope this helpsCode:Private Sub Command1_Click()
Dim o As New Outlook.Application, ns As Outlook.Namespace
Dim fldr As Outlook.MAPIFolder, ctcItems As Outlook.Items
Dim j As Integer
Set ns = o.GetNamespace("MAPI")
Set fldr = ns.GetDefaultFolder(olFolderContacts)
Set ctcItems = fldr.Items
For j = 1 To ctcItems.Count
On Error Resume Next ' in case you encounter a distribution list
List1.AddItem ctcItems.Item(j).FullName
Next j
End Sub
:wave:
what refrences do i need?
Microsoft Outlook xxx Object LibraryQuote:
Originally Posted by Mr_Zer0
Where xxx is the version nmber of your Outlook package :)
Cheers,
RyanJ
You don't have to use references when you use VBScript in VB just to let you know. ;)
But his code requires it.
There are a couple of variations of what you could do.
You could use VB Script behind a Outlook Form to do this.
You could use VB6 to automate it like posted.
You could use early binding like posted.
You could use late binding so it will work without any references (vb script or vb6).
'...
'...
If you don't want to add references
Code:Private Sub Command1_Click()
Dim o As Object, ns As Object
Dim fldr As Object, ctcItems As Object
Dim j As Integer
Dim ctc As Object
Set o = CreateObject("Outlook.Application")
Set ns = o.GetNamespace("MAPI")
Set fldr = ns.GetDefaultFolder(10)
Set ctcItems = fldr.Items
For j = 1 To ctcItems.Count
On Error Resume Next
List1.AddItem ctcItems.Item(j).FullName
Next j
End Sub