Importing into user-defined fields

  • Thread starter Thread starter Mark Rae
  • Start date Start date
M

Mark Rae

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
 
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
 
You'll kick yourself: You're saving the item before you're setting the custom property values.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
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...:-)
 
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.
 
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.
 
Back
Top