• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 412
  • Last Modified:

VBA code to export large number of custom contacts

I've written code in VBA to export a whole contacts folder to Excel, including nearly all built-in Outlook fields plus 100+ user fields. It loops through each contact and then through all properties in each contact. It's slow, averaging about 15 seconds per contact, and while most of my users will have 250-500 contacts, a few will have 2000-10,000. Is this method likely to be stable doing an export with potentially 1 million pieces of info to export? More importantly, is there a faster way for that many contacts? (I know about the cut and paste method but this needs to be idiotproof). Would CDO somehow help me? I know Redemption MAPITables can pull info from contacts quickly but that info still needs to be exported cell by cell.

Thanks, Adam
0
adampirg
Asked:
adampirg
  • 4
  • 2
1 Solution
 
_agj_Commented:
--> Is this method likely to be stable doing an export with potentially 1 million pieces of info to export?

shud be fine as long as u got DoEvents at the rite places to prevent system getting stuck.
0
 
_agj_Commented:
is this a standalone app/exe that uses excel and outlook objects?
or is it an excel template that fills itself?
0
 
_agj_Commented:
in outlook, in the file menu, u got an import/export option.

using the 'export to file' option under it, u can export to an excel sheet as well.

try it(i need to upgrade installation for that).
we cud automate this thing, if needed. simple vba.
0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
_agj_Commented:
what i mean is that:
one cud write code to do:
1 using the outlook object, export the contacts list to an excel sheet.
2. format this sheet if req., using the excel object.
Done.
0
 
adampirgAuthor Commented:
I have written VBA code, which I will probably put in a COM addin, to programmatically loop through each property of each contact in the folder, take the value of the property and insert it in Excel using objWS.Cells. All contacts are on custom forms, with 100+ custom fields each, so I can't use built-in export function. It will be run from a toolbar button within Excel, I think.

Where would I want DoEvents? I have it in there a couple times to call a separate Sub that updates the user on the progress of the export. Do I need it somewhere in the loop so every contact or every property does this? My core code:
        For Each objItem In objContactF.Items 'for each contact in the folder
           objSafeContact.Item = objItem  'sets Redemption SafeContactItem to this Contact
           intCol = 2 'reset to first column with each new contact
           For Each objProp In objSafeContact.ItemProperties 'reset to objSafeContact
                strValue = _
                    FormatForExcel(objSafeContact.ItemProperties.Item(objProp.Name).Value)
                objWS.Cells(intRow, intCol) = strValue
            intCol = intCol + 1
           Next 'Next property of the current contact
          intRow = intRow + 1
        Next 'Next contact in the folder
0
 
adampirgAuthor Commented:
I've read that Outlook has a memory leak when processing a large items collection with a for-next loop, and that using CDO may make it go faster or avoid this memory leak. Can you use CDO with contacts, or just with messages?
0
 
GhostModCommented:
PAQed, with points refunded (500)

GhostMod
Community Support Moderator
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now