Thanks a lot. Your code works well but i need to preserve the format of the cells as well. Like its dropping leading 0's and converting date to either dd/mm/yy format or mm/dd/yy format.
Please help me with that.
This post is over 5 years old, so he may not be paying attention to it anymore. Having said that, I'll try to help with your problem. Unfortunately, there is no way of preserving the format because a csv doesn't have a format. Excel puts things into the format that it thinks is a best fit.
One thing you can try is counting the rows and columns of your data, selecting that range in excel, and setting it to the format of your choosing (text is most likely to leave your data as it is). Alternatively, you could prefix every value in the csv with an apostrophe ('), to tell Excel to treat it as literal text. Neither of those solutions is very neat, but they should work.