Using VBA, how do I export Excel file as a CSV?

hollifd

Board Regular
Joined
Apr 3, 2002
Messages
248
Using VBA, how do I export Excel file as a CSV file? All help or comments will be appreciated.

Thanks,

David
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
I assume by "export", you want to save the file as a CSV. If so update this code:

ActiveWorkbook.SaveAs Filename:= _
"c:\MyFile.csv", FileFormat:=xlCSV _
, CreateBackup:=False

Regards
 
Upvote 0
I'm assuming the process would be the same if you wanted to go the other way: a CSV file to an XLS file. I tried this to no avail:

ActiveWorkbook.SaveAs Filename:= _
"c:\MyFile.xls", FileFormat:=xlXLS _
, CreateBackup:=False

I wasn't sure on what the FileFormat would be named, I think that's where my problem lies. Any ideas?

Thank you.
 
Upvote 0
FileFormat:= _
xlNormal

Silly of people to think that there would be any logic in file extentions! lol

Note - laughing at Excel, not you :biggrin:
 
Upvote 0
Hello guys,

When I automate a process to save an excel file to a csv the resulting csv has not Its data formatted into different columns (how I want it) but delimited with commas.

If I do the process I coded manually (by "saving as") It prompts me a message saying something that I may los some data but It does what I want... If I record that into a macro I get the usual code that you are discussing here, that doesn't do what I want

Any ideas?
 
Upvote 0
I have a similar problem. When I manually save an xls file into CSV, the date format is maintained, when I use the same macro code, dd/mm/yyyy is changed to mm/dd/yyyy which I cannot use.

Any suggestions?
 
Upvote 0
Thank you,

I'm moving jobs soon and there aren't allot of people who would understand that code if it broke. My crude but effective solution for now is to change the date format from 01/06/2010 to 01.06.2010. Seems to work.

Thanks for the help.

Stephen
 
Upvote 0

Forum statistics

Threads
1,213,487
Messages
6,113,938
Members
448,534
Latest member
benefuexx

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top