I\'m currently use this function for saving, but I have a problem with it:
Private Sub spara()
ActiveWorkbook.SaveAs Filename:=\"T:\\filepath+ ActiveWork
I had been looking this up to help resolve a similar issue I was having, I had an excel sheet that I export to a csv file, this is then uloaded elsewhere but requires the use of semicolons rather than commas for the character seperation, this worked fine when i was manually exporting the file as i had already changed the following Control Panel >> Region and Language >> additonal settings >> List separator from comma to semicolon. But when i tried to automate via VBA it defaulted back to comma, to fix I added the local paprameter as suggested by Christian Sauer above which then picks up the fact that i have changed my regional settings.
ActiveWorkbook.SaveAs Filename:="Filename.txt", FileFormat:=xlCSV, CreateBackup:=False, Local:=True
Thanks to Christian for the pointer.
It's quite possible this problem is not solvable using Excel VBA only. The problem is, while Excel Save As...
uses machine locale define list separator value, Excel VBA always uses en-US locale, thus, it always uses ,
as a list separator.
I would recommend saving a CSV and then use custom console app/script for postprocessing. There is plenty of CSV parsers available which can read a ,-csv
and then save it as ;-csv
.
I solved it adding "SaveChanges:=False" when closing workbook
With ActiveWorkbook
.SaveAs Filename:="T:\filepath+ ActiveWorkbook.Name", FileFormat:=xlCSV, Local:=True
.Close SaveChanges:=False
End With
Change Excel Options (Advanced, Editing options) to set Decimal separator to ,
(obviously (!))
Which language does your Excel use? If your native language uses ";" as default, you can pass the parameter "local:=True"
ActiveWorkbook.SaveAs Filename:="C:\Temp\Fredi.csv", FileFormat:=xlCSV, CreateBackup:=False, local:=True
If not, your only choice is searching and replacing afterwards...
For people having issues with this code
dim wa as Workbook
Workbooks.OpenText FileName:=path2file, _
DataType:=xlDelimited, Semicolon:=True, Local:=True
set wa = ActiveWorkbook
wa.SaveAs FileName:=path2file, FileFormat:=xlCSV, _ ConflictResolution:=xlLocalSessionChanges, Local:=True
wa.Close False
The second line is really important, if wa.Close False
is not there it will ask for approval to save, or if wa.Close True
it will replace the ";" for ",".
After going into local settings and making ";" the list delimiter, VBA was still separating with a ",". Modified the code to the above and it was done.
Hope this throw some light for some