Macro to Export Default Folders - Contacts Problem

  • Thread starter Thread starter Karl Burrows
  • Start date Start date
K

Karl Burrows

I have been working on a Macro that needs to work in Outlook XP and 2003.
The goal is to export the default folders (Contacts, Tasks, Calendar) to an
Excel file that will be used to 'sync' the files to the users other remote
computers using their VPN connection. I chose Excel to avoid the security
issues in Outlook. All folders except the Contacts will export perfectly,
but for some reason, I always get a stop error when it tries to export the
Contacts folder. I even tried the sample code MS provides to check the
export and it stops as well.

I am not master of VB and have a friend helping with the coding. It runs on
his computer (running XP with SP2 and 2003 with SP1) with no problems. Is
there a setting I have that is blocking this code or is there something
else. Here is the sample code that I ran to test the contacts access. It
runs through the code and I get an immediate stop at the Anniversary field.
I get the security prompts, etc. and then it just stops. What reference
files do I need to make the export work. I have the CDO and Excel 10
references checked.

Sub ExportContactsToText()
Dim OLF As Outlook.MAPIFolder, CurrUser As String
Dim EmailItemCount As Integer, i As Integer, EmailCount As Integer

Set OLF = GetObject("", _

"Outlook.Application").GetNamespace("MAPI").GetDefaultFolder(olFolderContact
s)
EmailItemCount = OLF.items.Count
i = 0: EmailCount = 0
' read e-mail information

Open ("C:\OutlookDataExport.dat") For Output As #1

While i < EmailItemCount
i = i + 1
'If Len(App.Path) <> 3 Then
'CfgFile = "C:\OutlookData.dat"
'Else
'CfgFile = App.Path & "cfg.dat"
'End If


With OLF.items(i)
EmailCount = EmailCount + 1
Print #1, .Anniversary
Print #1, .Birthday
Print #1, .Attachments.Count
Print #1, .UnRead
Print #1, .Body
Print #1, .Email1Address
Print #1, .Email1AddressType
Print #1, .Email1DisplayName
Print #1, .HomeAddress
Print #1, .HomeAddressCity
Print #1, .HomeAddressCountry
Print #1, .HomeAddressPostOfficeBox
Print #1, .HomeAddressPostalCode
Print #1, .HomeAddressState
Print #1, .HomeAddressStreet
Print #1, .HomeFaxNumber
Print #1, .HomeTelephoneNumber

End With
Wend
Close #1
Set OLF = Nothing

End Sub

Anyone have any ideas on how to get the contacts to export??? Is there
another approach that would work more efficiently???

Thanks so much!!!!
 
Not every item in a contacts folder is a ContactItem. The folder may also
contain distribution lists, which have different properties. You should
always check the Class property of the item before invoking item-specific
properties or methods.

FYI, there is a newsgroup specifically for general Outlook programming
issues "down the hall" at microsoft.public.outlook.program_vba or, via web
interface, at
http://www.microsoft.com/office/community/en-us/default.mspx?dg=microsoft.public.outlook.program_vba

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Thank you as always, Sue!

I'll go through the properties and see where I am getting kicked out.
 
It was the Distribution Lists! Are there any properties in particular that
I need to look at for this item. I assume it has a different message class,
but not sure how to "pick it out of the crowd."
 
PS Are there any other message classes in Contacts I should be on the
lookout for?

Thanks!!
 
As I said earlier, check the Class property. Only invoke
ContactItem-specific methods and properties when you know you have a
contact.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Back
Top