Jag ska göra en applikation som kan kommunicera med adressboken i outlook eller dylikt mailprogram. I ett exempel jag hittat ser det ut som man inte deklarerar något till typen AddressEntries utan istället Misstänker att ditt felmeddelande kommer sig av att du klippt och klistrat in kod från någon webbsida och inte har rätt referenser, dvs du måste lägga till en referens till Outlook:CDO i VB.NET 2003
Har kollat lite på en kod från Microsofts hemsida men när jag skriver in detta i mitt projekt (VB-projekt i VS.NET 2003) så klagar den direkt på deklarationerna under Dim objSession As MAPI.Session. Dvs: Dim objAddrEntries As AddressEntries, Dim objAddressEntry As AddressEntry och Dim objFilter As AddressEntryFilter. Den klagar på variabeltypen; Type 'AddressEntries' is not defined.
De flesta koderna jag har hittat ser ut som den nedan med samma deklaration. Vad ska jag göra?
Hela koden:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Const strServer = "MyServer"
Const strMailbox = "MyMailbox"
Dim objSession As MAPI.Session
Dim objAddrEntries As AddressEntries
Dim objAddressEntry As AddressEntry
Dim objFilter As AddressEntryFilter
Dim strProfileInfo As String
strProfileInfo = strServer & vbLf & strMailbox
objSession = CreateObject("MAPI.Session")
objSession.Logon(, , False, False, , True, strProfileInfo)
objAddrEntries = objSession.AddressLists _
("Global Address List").AddressEntries
objFilter = objAddrEntries.Filter
objFilter.Fields.Add(CdoPR_SURNAME, "LastName")
objFilter.Fields.Add(CdoPR_GIVEN_NAME, "FirstName")
On Error Resume Next
For Each objAddressEntry In objAddrEntries
Debug.Print(objAddressEntry.Name)
Debug.Print("E-address: " & objAddressEntry.Address)
Debug.Print("Given Name: " & _
objAddressEntry.Fields(CdoPR_GIVEN_NAME).Value)
Debug.Print("Initials: " & objAddressEntry.Fields _
(CdoPR_INITIALS).Value)
Debug.Print("Surname: " & objAddressEntry.Fields _
(CdoPR_SURNAME).Value)
Debug.Print("Display Name: " & objAddressEntry.Fields _
(CdoPR_DISPLAY_NAME).Value)
Debug.Print("Alias: " & _
objAddressEntry.Fields(CdoPR_ACCOUNT).Value)
Debug.Print("Title: " & _
objAddressEntry.Fields(CdoPR_TITLE).Value)
Debug.Print("Company Name: " & objAddressEntry.Fields _
(CdoPR_COMPANY_NAME).Value)
Debug.Print("Office Location: " & objAddressEntry.Fields _
(CdoPR_OFFICE_LOCATION).Value)
Debug.Print("Office Phone 1: " & objAddressEntry.Fields _
(CdoPR_OFFICE_TELEPHONE_NUMBER).Value)
Debug.Print("Office Phone 2: " & objAddressEntry.Fields _
(CdoPR_OFFICE2_TELEPHONE_NUMBER).Value)
Debug.Print("Business Fax: " & objAddressEntry.Fields _
(CdoPR_BUSINESS_FAX_NUMBER).Value)
Debug.Print("Mobile Phone: " & objAddressEntry.Fields _
(CdoPR_MOBILE_TELEPHONE_NUMBER).Value)
Debug.Print("Pager: " & objAddressEntry.Fields _
(CdoPR_PAGER_TELEPHONE_NUMBER).Value)
Debug.Print("Assistant: " & objAddressEntry.Fields _
(CdoPR_ASSISTANT).Value)
Debug.Print("Assistant Phone: " & objAddressEntry.Fields _
(CdoPR_ASSISTANT_TELEPHONE_NUMBER).Value)
Debug.Print("Home Phone 1: " & objAddressEntry.Fields _
(CdoPR_HOME_TELEPHONE_NUMBER).Value)
Debug.Print("Home Phone 2: " & objAddressEntry.Fields _
(CdoPR_HOME2_TELEPHONE_NUMBER).Value)
Debug.Print("Home Fax: " & objAddressEntry.Fields _
(CdoPR_HOME_FAX_NUMBER).Value)
Debug.Print("Home Street: " & objAddressEntry.Fields _
(CdoPR_HOME_ADDRESS_STREET).Value)
Debug.Print("Home City: " & objAddressEntry.Fields _
(CdoPR_HOME_ADDRESS_CITY).Value)
Debug.Print("Home State: " & objAddressEntry.Fields _
(CdoPR_HOME_ADDRESS_STATE_OR_PROVINCE).Value)
Debug.Print("Home Postal Code: " & objAddressEntry.Fields _
(CdoPR_HOME_ADDRESS_POSTAL_CODE).Value)
Debug.Print("Home Country: " & objAddressEntry.Fields _
(CdoPR_HOME_ADDRESS_COUNTRY).Value)
Debug.Print("Manager Name: " & objAddressEntry.Fields _
(CdoPR_MANAGER_NAME).Value)
Debug.Print("Manager Name: " & objAddressEntry.Manager)
Next
objSession.Logoff()
objFilter = Nothing
objAddrEntries = Nothing
objSession = Nothing
End Sub
Sv: CDO i VB.NET 2003
MAPI.AddressList
Dim objSession As New MAPI.Session
Dim objAdds As MAPI.AddressLists
Dim objAddress As MAPI.AddressEntry
Dim objGAL As MAPI.AddressList
Dim objFields As MAPI.Fields, objField As MAPI.Field
objSession.Logon , , , False
If objSession Is Nothing Then Exit Sub
Set objAdds = objSession.AddressLists
Set objGAL = objAdds.Item("Global Address List") '<<<<======
For Each objAddress In objGAL.AddressEntries
If objAddress.DisplayType = CdoUser Or objAddress.DisplayType =
CdoRemoteUser Then
Hoppas det löser dina problem.
Resten av koden hittas på
http://forums.wugnet.com/office/Download-Address-Book-ftopict601914.html
/JesperSv: CDO i VB.NET 2003
Högerklicka på References -> Add reference -> COM -> Microsoft Outlook 10 Object Library
Microsoft Outlook 10 Object Library gäller om du har Outlook XP (2002) installerat
Microsoft Outlook 11 Object Library för Outlook 2003