Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 661
Default VBA code to create new Contacts field in Outlook

I want to check Outlook Contacts to see if a field exists and if not then to
create it. Please can anyone help me with the code for this?

I have tried the following to create a field but without success:

dim objContacts as outlook.application
Set myProp = objContacts.UserProperties.Add("MyNewField", olText)

Please help. Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA code to create new Contacts field in Outlook


Hello Paul

I hope this help you



Add a contact

Sub AddContactOutlook()
'activate Microsoft Outlook xx.x Object Library
Dim objOutlook As New Outlook.Application
Dim objContact As contactItem

Set objContact = objOutlook.createItem(olContactItem)

With objContact
..email1Address = "
..FirstName = "firstName"
..lastName = "lastName"
..homeTelephoneNumber = "00 00 00 00 00"
..homeAddressCity = "theCity"
..Save
End With
End Sub



control if a firstName exist in the contacts list

Sub controleFirstName_contactsOutlook()
'activate Microsoft Outlook xx.x Object Library
Dim olApp As New Outlook.Application
Dim Cible As Outlook.contactItem
Dim dossierContacts As Outlook.MAPIFolder

Set olApp = New Outlook.Application
Set dossierContacts =
olApp.GetNamespace("MAPI").GetDefaultFolder(olFold erContacts)

Set Cible = dossierContacts.Items.Find("[FirstName] = ""firstName""")
If Not Cible Is Nothing Then
MsgBox "Exist"
Else
MsgBox "Does not exist"
End If
End Sub



Regards,
michel


--
michelxld
------------------------------------------------------------------------
michelxld's Profile: http://www.excelforum.com/member.php...o&userid=17367
View this thread: http://www.excelforum.com/showthread...hreadid=478209

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 661
Default VBA code to create new Contacts field in Outlook



"michelxld" wrote:


Hello Paul

I hope this help you



Add a contact

Sub AddContactOutlook()
'activate Microsoft Outlook xx.x Object Library
Dim objOutlook As New Outlook.Application
Dim objContact As contactItem

Set objContact = objOutlook.createItem(olContactItem)

With objContact
.email1Address = "
.FirstName = "firstName"
.lastName = "lastName"
.homeTelephoneNumber = "00 00 00 00 00"
.homeAddressCity = "theCity"
.Save
End With
End Sub



control if a firstName exist in the contacts list

Sub controleFirstName_contactsOutlook()
'activate Microsoft Outlook xx.x Object Library
Dim olApp As New Outlook.Application
Dim Cible As Outlook.contactItem
Dim dossierContacts As Outlook.MAPIFolder

Set olApp = New Outlook.Application
Set dossierContacts =
olApp.GetNamespace("MAPI").GetDefaultFolder(olFold erContacts)

Set Cible = dossierContacts.Items.Find("[FirstName] = ""firstName""")
If Not Cible Is Nothing Then
MsgBox "Exist"
Else
MsgBox "Does not exist"
End If
End Sub



Regards,
michel


--
michelxld
------------------------------------------------------------------------
michelxld's Profile: http://www.excelforum.com/member.php...o&userid=17367
View this thread: http://www.excelforum.com/showthread...hreadid=478209


Thank you michelxd but this is not what I was after.

I have about 250 contacts in Outlook. I also have an Excel address book that
I have created with about 50 fields, 6 of which do not appear in the
'standard' Outlook list of contact fields.

For instance my Excel address book has fields for the details of a partner's
name ie Title2, FirstName2, LastName2, Birthday2 etc.

What I want to do is to create extra fields for each contact in the Outlook
contacts so that I can upload the Excel field values into Outlook.
For example, if my first contact is 'FileAs' = "Bloggs, Fred" then I wish to
add a field entitled "Title2" for that contact and enter the value "Mrs", add
the filed "FirstName2" and enter the value "Freda", add the field "LastName2"
and enter the value "Bloggs".

I can add a UserProperty field to the ContactsFolder but cannot get to add
the field into each contact.

Any ideas please?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA code to create new Contacts field in Outlook


Hello Paul

sorry , i don't undersand your question

this example controls if a UserProperty named "MyCustomField" exist
(for all contatcs) , and add it if does not exist


Sub control_Or_Add_userProperty_contactsOutlook()
'activate Microsoft Outlook xx.x Object Library
Dim olApp As New Outlook.Application
Dim Cible As Outlook.contactItem
Dim dossierContacts As Outlook.MAPIFolder
Dim myProp As Outlook.UserProperty

Set olApp = New Outlook.Application
Set dossierContacts =
olApp.GetNamespace("MAPI").GetDefaultFolder(olFold erContacts)

For Each Cible In dossierContacts.Items
Set myProp = Cible.UserProperties("MyCustomField")

If myProp Is Nothing Then
Set myProp = Cible.UserProperties.Add("MyCustomField", olText)
myProp.Value = "My data"
Cible.Save
End If

Next
End Sub


Regards ,
michel


--
michelxld
------------------------------------------------------------------------
michelxld's Profile: http://www.excelforum.com/member.php...o&userid=17367
View this thread: http://www.excelforum.com/showthread...hreadid=478209

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 661
Default VBA code to create new Contacts field in Outlook

Hello Michel

Thanks for the post - I can now see the light.

Many thanks

Paul


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default VBA code to create new Contacts field in Outlook

I tried your code - I get an error "'91' object variable or with block
variable not set" when it hits the 'set'. Most frustrating. Ideas

"michelxld" wrote:


Hello Paul

I hope this help you



Add a contact

Sub AddContactOutlook()
'activate Microsoft Outlook xx.x Object Library
Dim objOutlook As New Outlook.Application
Dim objContact As contactItem

Set objContact = objOutlook.createItem(olContactItem)

With objContact
.email1Address = "
.FirstName = "firstName"
.lastName = "lastName"
.homeTelephoneNumber = "00 00 00 00 00"
.homeAddressCity = "theCity"
.Save
End With
End Sub



control if a firstName exist in the contacts list

Sub controleFirstName_contactsOutlook()
'activate Microsoft Outlook xx.x Object Library
Dim olApp As New Outlook.Application
Dim Cible As Outlook.contactItem
Dim dossierContacts As Outlook.MAPIFolder

Set olApp = New Outlook.Application
Set dossierContacts =
olApp.GetNamespace("MAPI").GetDefaultFolder(olFold erContacts)

Set Cible = dossierContacts.Items.Find("[FirstName] = ""firstName""")
If Not Cible Is Nothing Then
MsgBox "Exist"
Else
MsgBox "Does not exist"
End If
End Sub



Regards,
michel


--
michelxld
------------------------------------------------------------------------
michelxld's Profile: http://www.excelforum.com/member.php...o&userid=17367
View this thread: http://www.excelforum.com/showthread...hreadid=478209


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I export contacts from Excel back to Outlook Contacts? corvettego Excel Discussion (Misc queries) 2 August 17th 09 06:29 PM
export outlook contacts ? miket Excel Discussion (Misc queries) 1 October 25th 08 10:22 PM
Import contacts from outlook Bob Levin Excel Discussion (Misc queries) 10 September 10th 08 10:12 PM
outlook contacts lee Excel Discussion (Misc queries) 0 October 25th 05 08:40 PM
I could really need your help on importing contacts into Outlook (Please?) Jos[_2_] Excel Programming 8 November 17th 03 03:24 AM


All times are GMT +1. The time now is 03:32 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"