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!!!!
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!!!!