copyright 1999 - 2014 by heinz prelle - hannover  - lenbachstraße 42 - www.visual-basic5.de | impressum
'Beispiel: VB .Net - Outlook - Kontaktordner auslesen - 2
'Hinweis : Referenzieren Sie zu: Microsoft Outlook Object Library 12.0
'
Option Explicit On
Option Strict On

Imports Microsoft.Office.Interop

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles Button1.Click
        Try
            Dim TList As New List(Of String)(Me.Outlook_GetContactItems())
            If TList IsNot Nothing Then
                For Each items As String In TList
                    Me.ListBox1.Items.Add(items)
                Next
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message.ToString(), "Info")
        End Try
    End Sub

    Private Function Outlook_GetContactItems() As List(Of String)
        Try
            Dim Instance As Outlook.Application = New Outlook.Application()
            Dim ns As Outlook.NameSpace = Nothing
            Dim mapi As Outlook.MAPIFolder = Nothing
            ns = Instance.GetNamespace("MAPI")

            mapi = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
            Dim Items As Outlook.Items = mapi.Items.Restrict("[MessageClass] = 'IPM.Contact'")
            Items.Sort("[EMail1Address]", False)
            Dim TList As New List(Of String)
            For Each item As Outlook.ContactItem In Items
                TList.Add(item.CompanyName & " | " & item.BusinessTelephoneNumber)
            Next
            Return TList
        Catch
            Return Nothing
        End Try
        Return Nothing
    End Function

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles MyBase.Load
        Me.CenterToScreen()
    End Sub

End Class