Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Contacts / June 2005

Tip: Looking for answers? Try searching our database.

Importing into user-defined fields

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mark Rae - 02 Jun 2005 11:38 GMT
Hi,

Apologies if this is a frequently-asked question...

I need to import a set of contacts from an Excel 2003 spreadsheet into a
public contacts folder viewed through Outlook 2003.

From a cursory search through Google, it looks as if this isn't possible
through the built-in File Import functionality.

Is there an easy way to do this, or am I going to have to do it
programmatically?

Any assistance gratefully received.

Best regards,

Mark Rae
Sue Mosher [MVP-Outlook] - 02 Jun 2005 13:09 GMT
Outlook doesn't support importing to a custom form. You'd have to write custom code or use a third-party application. See http://www.outlookcode.com/d/customimport.htm.
Signature

Sue Mosher, Outlook MVP
Author of
    Microsoft Outlook Programming - Jumpstart for
    Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx

> Hi,
>
[quoted text clipped - 14 lines]
>
> Mark Rae
Mark Rae - 02 Jun 2005 13:54 GMT
>Outlook doesn't support importing to a custom form. You'd have to write
>custom code or use a third-party application. See
>http://www.outlookcode.com/d/customimport.htm.

I think I'm pretty much there, though the user properties behaviour is
proving to be a little tricky... I decided to write the code in Excel VBA,
since the contacts to be imported are in Excel anyway.

Basically, the contact gets created OK, and the user-defined fields get
created in the folder but not in the actual contact item. If I change the
third argument of the UserProperties.Add method to False, the UDFs don't get
created at all... The code I'm using is below:

Sub ExportToOutlook()

On Error GoTo ExportToOutlook_Error

Dim objOL As New Outlook.Application
Dim objNS As Outlook.Namespace
Dim objFolder As Outlook.MAPIFolder
Dim objContact As Outlook.ContactItem
Dim objProperty As Outlook.UserProperty

Set objNS = objOL.GetNamespace("MAPI")

Set objFolder =
objNS.GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders("Caledonia
Contacts")

Set objContact = objFolder.Items.Add("IPM.Contact")
objContact.FirstName = "Mark"
objContact.LastName = "Rae"
objContact.Close (olSave)

Set objProperty = objContact.UserProperties.Add("Test", olText, True)
objProperty = "Test"

Set objProperty = objContact.UserProperties.Add("Chelsea", olYesNo, True,
olYesNo)
objProperty = True

ExportToOutlook_Exit:
   Set objProperty = Nothing
   Set objContact = Nothing
   Set objFolder = Nothing
   Set objNS = Nothing
   Set objOL = Nothing
   Exit Sub
ExportToOutlook_Error:
   MsgBox Err.Description, vbCritical + vbOKOnly, "Error In
ExportToOutlook"
   Resume ExportToOutlook_Exit
End Sub
Sue Mosher [MVP-Outlook] - 02 Jun 2005 14:05 GMT
You'll kick yourself: You're saving the item before you're setting the custom property values.

Signature

Sue Mosher, Outlook MVP
Author of
    Microsoft Outlook Programming - Jumpstart for
    Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx

>>Outlook doesn't support importing to a custom form. You'd have to write
>>custom code or use a third-party application. See
[quoted text clipped - 49 lines]
>    Resume ExportToOutlook_Exit
> End Sub
Mark Rae - 02 Jun 2005 14:45 GMT
>You'll kick yourself: You're saving the item before you're setting the
>custom property values.

ROTFLMAO!!!

I wish to be known as TAOTH (the anus of the horse) for the rest of the
day...:-)
Mark Rae - 02 Jun 2005 17:01 GMT
Hi Sue,

Can you please tell me how to specify the "This is the mailing address"
functionality when importing from Excel? I'm using the following code:

   objContact.BusinessAddressStreet = Range("I" & intRow).Value
   If Range("J" & intRow).Value <> "" Then
       objContact.BusinessAddressStreet = objContact.BusinessAddressStreet
& vbCrLf & Range("J" & intRow).Value
   End If
   If Range("K" & intRow).Value <> "" Then
       objContact.BusinessAddressStreet = objContact.BusinessAddressStreet
& vbCrLf & Range("K" & intRow).Value
   End If
   objContact.BusinessAddressCity = Range("L" & intRow).Value
   objContact.BusinessAddressState = Range("M" & intRow).Value
   objContact.BusinessAddressPostalCode = Range("N" & intRow).Value
   objContact.BusinessAddressCountry = Range("O" & intRow).Value
   objContact.HomeAddressStreet = Range("P" & intRow).Value
   If Range("Q" & intRow).Value <> "" Then
       objContact.HomeAddressStreet = objContact.HomeAddressStreet & vbCrLf
& Range("Q" & intRow).Value
   End If
   If Range("R" & intRow).Value <> "" Then
       objContact.HomeAddressStreet = objContact.HomeAddressStreet & vbCrLf
& Range("R" & intRow).Value
   End If
   objContact.HomeAddressCity = Range("S" & intRow).Value
   objContact.HomeAddressState = Range("T" & intRow).Value
   objContact.HomeAddressPostalCode = Range("U" & intRow).Value
   objContact.HomeAddressCountry = Range("V" & intRow).Value

If there is not a home address, then all is well. However, the business
rules say that if there is a home address, it must be the mailing address. I
tried the following code:

   If objContact.HomeAddress <> "" Then
       objContact.MailingAddress = objContact.HomeAddress
   Else
       objContact.MailingAddress = objContact.BusinessAddress
   End If

However, that also added a business address and made it the mailing address.

Any assistance gratefully received.
Mark Rae - 02 Jun 2005 22:34 GMT
> Can you please tell me how to specify the "This is the mailing address"
> functionality when importing from Excel? I'm using the following code:

S'OK - I figured it out. It's the SelectedMailingAddress property.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.