Excel formatting for date is not working when exporting as XML

NonProgrammer picture NonProgrammer · Jun 14, 2013 · Viewed 10k times · Source

I have created an Excel that includes a mapping file. What I am trying to do is have users enter the data in here and press ctrl + E (I created a macro) and it would export it out as XML. Here's the issue: When line 1 gets exported, it keeps its date and time format in XML (Example: In XML, time will show up as 12/01/2013). But anything entered under that line will not show up in the format I want. Instead, it will show up as 1345464 for date.

This thing has been very annoying because I cannot figure out what I can do to format the whole Excel document/column so it will show the date and time as text instead of weird number.

Someone please help me out.

Answer

Jack picture Jack · Jun 14, 2013

In VBA, use the Format function

date = Format(date, "mm/dd/yyyy")

Then change the format of the cell you store it in:

Cells(row, col).NumberFormat = "@"

(substitute your cell's coordinates for row and col)