ERLANDSEN DATA CONSULTING Excel & VBA Tips   Information in English / Informasjon på engelsk

Disse websidene oppdateres ikke lengre og er kun tilgjengelig for historikken sin skyld.

Klikk her for å gå til den oppdaterte informasjonen.

Hent kontaktinformasjon fra Outlook

Eksempelfunksjonen neddenfor kan benyttes til å returnere kontaktinformasjon fra Kontakt-mappen i Outlook, man trenger bare å angi kontaktnavnet og hva slags informasjon man vil at funksjonen skal returnere. Funksjonen kan utvides til å returnere all lagret informasjon for en kontakt.

Function GetContactInfoFromOutlook(strFullName As String, strReturnItem As String) As String
' benyttes slik i en regnearkcelle, forutsetter at celle A1 inneholder et navn:
' =GetContactInfoFromOutlook(A1,"E-mail")
' =GetContactInfoFromOutlook(A1,"Phone")
' =GetContactInfoFromOutlook(A1,"Mobile")
Dim OLF As Object, olContactItem As Object
Dim OK As Boolean, i As Long, strResult As String
    On Error Resume Next
    Set OLF = GetObject("", "Outlook.Application").GetNamespace("MAPI").GetDefaultFolder(10)
    If OLF Is Nothing Then
        Set OLF = CreateObject("Outlook.Application").GetNamespace("MAPI").GetDefaultFolder(10)
    End If
    On Error GoTo 0
    If Not OLF Is Nothing Then
        With OLF
            OK = False
            i = 0
            Do While i < .Items.Count And Not OK
                i = i + 1
                On Error Resume Next
                Set olContactItem = .Items(i)
                On Error GoTo 0
                If Not olContactItem Is Nothing Then
                    With olContactItem
                        If .FullName = strFullName Then
                            OK = True
                            Select Case LCase(strReturnItem)
                                Case "mail", "e-mail"
                                    strResult = .Email1Address
                                Case "phone", "home phone"
                                    strResult = .HomeTelephoneNumber
                                Case "mobile", "cell", "cellphone", "carphone"
                                    strResult = .MobileTelephoneNumber
                                ' add more if necessary
                                Case Else ' default result
                                    strResult = .Email1Address
                            End Select
                        End If
                    End With
                    Set olContactItem = Nothing
                End If
            Loop
        End With
        Set OLF = Nothing
    End If
    GetContactInfoFromOutlook = strResult
End Function

NB! Outlook vil presentere advarselsdialogen om mulig virus når denne funksjonen benyttes!

 

Dokumentet er sist oppdatert 2007-08-13 10:38:58      Utskriftsvennlig versjon

 

Erlandsen Data Consulting     http://www.erlandsendata.no/   
Excel & VBA Tips   Copyright ©1999-2024    Ole P. Erlandsen   All rights reserved
E-post kontaktadresse