PDA

View Full Version : export XML from Outlook Contacts



steve_flash
10-22-2011, 07:50 PM
long story short I need to export contacts from Outlook in XML format so that flash based photo ID badge creator like this one quickidcard.com (http://www.quickidcard.com) can take it. I got it somehow going with PST export and then parse, far from smooth. Holy grail would be Outlook macro creating badges, kind of like mail merge. Does this sound unreal or just plain difficult? It would need to fly in Outlook 2010 32bit and 2007. No Exchange touching allowed, has to be purely client side.
Thanks

JP2112
10-27-2011, 09:55 AM
Do they take any other kind of formats? Outlook can export to VCF.

steve_flash
10-27-2011, 12:51 PM
I was thinking about vCard too, even expected that it's somehow XML but no luck. The ID badge creator takes only XML directly, everything else means parsing. The client is also not easiest one. Unless I say it's impossible they assume it's bullet proof

JP2112
10-31-2011, 09:16 AM
Ha, ok, have you considered looping through the contacts folder and creating your own XML files? Or exporting contacts manually, opening the file with Excel and then creating the XML like this?


Sub makexml()
Dim entries As Variant
entries = Range("A1").CurrentRegion.value
WriteXMLFile (entries)
End Sub
Function WriteXMLFile(entries As Variant) As String
Dim xmlDoc As MSXML2.DOMDocument60
Dim rootelem As MSXML2.IXMLDOMNode
Dim valuesNode As MSXML2.IXMLDOMNode
Dim valueNode As MSXML2.IXMLDOMNode
Dim pi As MSXML2.IXMLDOMNode
Dim numberOfRecords As Long
Dim numberOfFields As Long
Dim i As Long, j As Long
' loop through each record, creating nodes along the way
numberOfRecords = UBound(entries) - 1
numberOfFields = UBound(entries, 2)
' create MSXML 6.0 document for each Excel row
For i = 1 To numberOfRecords
Set xmlDoc = New MSXML2.DOMDocument60
' add XML declaration at top of file
Set pi = xmlDoc.createProcessingInstruction("xml", "version='1.0' encoding='UTF-8'")
xmlDoc.appendChild pi
' create root element
Set rootelem = xmlDoc.createElement("Contact")
xmlDoc.appendChild rootelem
Set valuesNode = xmlDoc.createElement("Values")
rootelem.appendChild valuesNode
For j = 1 To numberOfFields
Set valueNode = xmlDoc.createElement(Replace(entries(1, j), " ", ""))
valueNode.nodeTypedValue = entries(i + 1, j)
valuesNode.appendChild valueNode
Next j

xmlDoc.Save "Q:\" & entries(i + 1, 1) & ".xml"
Next i
End Function

steve_flash
11-02-2011, 05:24 AM
thanks for this code. I have something similar in place. It works fine up to like 20-30 contacts. When I need to process 50 and over you can see there is room for performance improvement