basica
asked on
Adding Entry to Outlook Address Book
I'm trying to add an address entry to the outlook address book. I found this code in another section but can't get it to work even after adding MAPI components and referencing outlook.
Here's the code:
Function AddEntry()
Dim objSession As MAPI.Session ' Session object
Dim objMyPAB As AddressList ' personal address book object
Dim objNewEntry As AddressEntry ' new address entry object
Dim propTag As Long ' MAPI property tag for new field
On Error GoTo error_olemsg
Set objSession = CreateObject("MAPI.Session ")
' log on to session, supplying username and password
objSession.Logon 'profileName:="MyProfile", _
'profilePassword:="my_pass word"
' get PAB AddressList from AddressLists collection of Session
Set objMyPAB = objSession.AddressLists("P ersonal Address Book")
If objMyPAB Is Nothing Then
MsgBox "Invalid PAB from session"
Exit Function
End If
' add new AddressEntry to AddressEntries collection of AddressList
Set objNewEntry = objMyPAB.AddressEntries.Ad d "SMTP", "Jane Doe"
objNewEntry.address = "janed@exchange.microsoft. com"
' set MAPI property in new AddressEntry (don’t need to Add it)
propTag = &H3A08001E ' VB4.0: ActMsgPR_BUSINESS_TELEPHON E_NUMBER
objNewEntry.Fields(propTag ) = “+1-206-555-9901”
' add custom property to new AddressEntry and set its value
objNewEntry.Fields.Add “CellularPhone”, vbString
objNewEntry.Fields(“Cellul arPhone”) = “+1-206-555-9902”
' commit new entry, properties, fields, and values to PAB AddressList
objNewEntry.Update
MsgBox “New address book entry successfully added”
Exit Function
error_olemsg:
MsgBox "Error " & Str(Err) & ": " & Error$(Err)
Exit Function ' so many steps to succeed; just exit on error
End Function
I've put it all in a module and call the procedure - I keep getting this error: user defined type not defined ... on this line....
dim objSession As MAPI.Session
Here's the code:
Function AddEntry()
Dim objSession As MAPI.Session ' Session object
Dim objMyPAB As AddressList ' personal address book object
Dim objNewEntry As AddressEntry ' new address entry object
Dim propTag As Long ' MAPI property tag for new field
On Error GoTo error_olemsg
Set objSession = CreateObject("MAPI.Session
' log on to session, supplying username and password
objSession.Logon 'profileName:="MyProfile",
'profilePassword:="my_pass
' get PAB AddressList from AddressLists collection of Session
Set objMyPAB = objSession.AddressLists("P
If objMyPAB Is Nothing Then
MsgBox "Invalid PAB from session"
Exit Function
End If
' add new AddressEntry to AddressEntries collection of AddressList
Set objNewEntry = objMyPAB.AddressEntries.Ad
objNewEntry.address = "janed@exchange.microsoft.
' set MAPI property in new AddressEntry (don’t need to Add it)
propTag = &H3A08001E ' VB4.0: ActMsgPR_BUSINESS_TELEPHON
objNewEntry.Fields(propTag
' add custom property to new AddressEntry and set its value
objNewEntry.Fields.Add “CellularPhone”, vbString
objNewEntry.Fields(“Cellul
' commit new entry, properties, fields, and values to PAB AddressList
objNewEntry.Update
MsgBox “New address book entry successfully added”
Exit Function
error_olemsg:
MsgBox "Error " & Str(Err) & ": " & Error$(Err)
Exit Function ' so many steps to succeed; just exit on error
End Function
I've put it all in a module and call the procedure - I keep getting this error: user defined type not defined ... on this line....
dim objSession As MAPI.Session
perhaps this code will give you some ideas
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.