VBA Excel - Saving .csv with semicolon as separator

tvbolt

New Member
Joined
Mar 20, 2019
Messages
3
Hi everyone,

I came across a problem with the task currently at hand:

I need to save a file as .csv with a semicolon as separator. My Windows regional settings also have a semicolon as list separator. When I manually save the file as csv (or even manually save a macro generated .csv before closing it) it works totally fine, I get a nice file that has a semicolon as separator and looks like a normal excel table.

Nevertheless, when I save and close the file with VBA code, and then reopen it I get a very curious picture: the data is separated by commas.

Below is the piece of code that I use regarding the workbook I need to save as .csv. Any tips on how to fix this?

Thanks a lot for your help!

Code:
Set csv = Workbooks.Add(xlWBATWorksheet)
csv.SaveAs Filename:=path & "\template.csv", FileFormat:=xlCSV
'some code to fill the .csv file with data
csv.Save
csv.Close
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Welcome to the Board!

When I manually save the file as csv (or even manually save a macro generated .csv before closing it) it works totally fine,
If it works when you do it manually, try turning on the Macro Recorder and record yourself performing those steps. Then stop the recorder and view the VBA code that creates. Compare that to the code you have, and see if it is just a matter of making a few simple changes.

Nevertheless, when I save and close the file with VBA code, and then reopen it I get a very curious picture: the data is separated by commas.
What program are you using to view the CSV file?
If you REALLY want to see what is contained in the CSV file, DON'T use Excel to view it! Excel does automatic conversions on data as it sees fit. Use a Text Editor, like NotePad or WaordPad to view the CSV file to see what it really looks like.
 
Upvote 0
Hi, welcome to the forum!

You could try this addition to your saveas line;

Rich (BB code):
csv.SaveAs Filename:=Path & "\template.csv", FileFormat:=xlCSV, Local:=True
 
Upvote 0
Thanks everyone for the welcome!

What program are you using to view the CSV file?
If you REALLY want to see what is contained in the CSV file, DON'T use Excel to view it! Excel does automatic conversions on data as it sees fit. Use a Text Editor, like NotePad or WaordPad to view the CSV file to see what it really looks like.

Thanks a lot for your reply, but I was actually opening it with Notepad, and still commas were there. Recording a macro didn't help either. The code is completely the same.

Hi, welcome to the forum!

You could try this addition to your saveas line;

Rich (BB code):
csv.SaveAs Filename:=Path & "\template.csv", FileFormat:=xlCSV, Local:=True

Thanks, I totally forgot about Local parameter. For a minute there I actually thought it was the solution, but unfortunately it didn't work either. :(
 
Upvote 0
Did you take a look at the options presented in the link Jim posted?
 
Upvote 0
Did you take a look at the options presented in the link Jim posted?
Yeah, I have. By the way, thanks, Jim.

The only acceptable option for me there is actually the VBA code which goes row by row and concatenates all cells in a row with a semicolon between them.

I already had something similar in my code for the users who have a comma as separator in Windows regional settings. Currently I have removed the 'comma' condition and had the code running regardless of global region settings. So, my VBA code works fine, but I would still love to know why it was working this way. I'm kind of confused with this and would really appreciate it if someone could explain what was happening there and why.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,021
Latest member
Justyna P

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