Saveas csv file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to save a xls file as csv.
When I save it manualy by using saveas, and choosing csv format in the drop
down box, everything is OK.
But when I try to program it in VB, all the data is put in column A.

Can anybody help?
 
Hi

Yes. When i juse the recorder, all the data is arrangende in column A
Regards Fib

"Ivan Raiminius" skrev:
 
Hi,

so, you are using:

workbooks("some workbook").SaveAs Filename:= _
"some filename(including path).csv" _
, FileFormat:=xlCSV, CreateBackup:=False

in your code?

Regards,
Ivan
 
Hi
My code is:
Windows("record.xls").Activate
ActiveWorkbook.SaveAs "F:\record.csv", FileFormat:=xlcsv

I have tryed this one as well, but havent been able to create the same
format, like the format when I am saving it manualy.

Windows("record.xls").Activate
Const xlcsv = 1 '(I have tryed every number from 1 to 100. )
ActiveWorkbook.SaveAs "F:\record.csv", FileFormat:=xlcsv

Best regards Fib

"Ivan Raiminius" skrev:
 
Hi,

xlcsv = 6

your code should work. What is the exact problem? What do you see when
you open your .csv file in Notepad? and in Excel?

Regards,
Ivan
 
Hi

When I use the code xlcsv = 6, it puts all the data in column A.

Regards Fib

"Ivan Raiminius" skrev:
 
Hi,

I understand, I am asking what you see in Notepad if you open the .csv
file in it. In Excel you see all values in column A, separated by
comma?

Regards,
Ivan
 
Hi.
That is correct.
In notepad the values are all separated by semicolons when saved manualy
Saved with VB the values are all separated by comma.

"Ivan Raiminius" skrev:
 
Hi,

and you use as delimiter (in formulas) semicolon rather then comma?

The behaviour you are describing is OK. The file should be separated by
commas (csv = Comma Separated Values).

The problem is caused by your column delimiter (which is set to be
semicolon ";" instead of comma ","), so your columns are not
recognized.

You can use this to open the .csv (comma separated) file with columns
recognized:
Workbooks.OpenText filename:="filename", _
dataType:=xlDelimited, comma:=True

or you can save it with semicolons as delimiter using:
workbooks("some workbook").SaveAs Filename:= _
"some filename(including path).csv" _
, FileFormat:=xlCSV, CreateBackup:=False, local:=true

I hope it helped.

Regards,
Ivan
 
Hi Ivan

You are a genious. I have tried to solve this problem for weeks. Thank you
very much.

Best regards Fib

"Ivan Raiminius" skrev:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top