use vba creat csv but the format of csv is not correct.

dadario

New Member
Joined
Jul 27, 2010
Messages
3
<TABLE sizset="14" sizcache="6"><TBODY sizset="14" sizcache="6"><TR sizset="14" sizcache="6"><TD class=votecell>




</TD><TD class=postcell sizset="14" sizcache="6">I use the code as below.
Private Sub CommandButton1_Click()
Const File$ = "C:\CsvfileTest2.csv"
Dim Fso, MyFile
Set Fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = Fso.CreateTextFile(File, True)
MyFile.Close
With CreateObject("ADODB.Stream")
.Open
.LoadFromFile File
.Position = 0
.Charset = "UTF-8"
.SaveToFile File, 2
.Close
End With
'Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set MyFile = Fso_OpenTextFile(File, 8, True, True)
' Just for the example:
myrange1 = 10
box = ""
For i = 1 To myrange1
box = ""

<CODE> For j = 1 To 10 </CODE>
<CODE> box = box & Sheet1.Cells(i, j) & ChrW(44)</CODE>
<CODE> Next j </CODE>



</PRE>MyFile.WriteLine box
Next i
MyFile.Close
End Sub
the file which I creat is not a realy csv. can anybody help me?





</TD></TR></TBODY></TABLE></P>
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
<TABLE sizcache="6" sizset="14"><TBODY sizcache="6" sizset="14"><TR sizcache="6" sizset="14"><TD class=votecell>





</TD><TD class=postcell sizcache="6" sizset="14">I use the code as below.
Private Sub CommandButton1_Click()
Const File$ = "C:\CsvfileTest2.csv"
Dim Fso, MyFile
Set Fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = Fso.CreateTextFile(File, True)
MyFile.Close
With CreateObject("ADODB.Stream")
.Open
.LoadFromFile File
.Position = 0
.Charset = "UTF-8"
.SaveToFile File, 2
.Close
End With
'Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set MyFile = Fso_OpenTextFile(File, 8, True, True)
' Just for the example:
myrange1 = 10
box = ""
For i = 1 To myrange1
box = ""

<CODE>For j = 1 To 10 </CODE>
<CODE>box = box & Sheet1.Cells(i, j) & ChrW(44)</CODE>
<CODE>Next j </CODE>





</PRE>MyFile.WriteLine box
Next i
MyFile.Close
End Sub
the file which I creat is not a realy csv. can anybody help me?


</TD></TR></TBODY></TABLE></P>

Can you explain exactly what you are trying to achieve. It's not clear, to me anyway.
 
Upvote 0
1 I want to creat a csv file which has a content of french.
2 So I write excel sheet content to csv file(the range is A1 to J10)
3 And I creat a utf-8 csv file
4 My program can write the content to csv file. but this csv file have problem.
lf I DOUBLE CLICK it, it will appeare like this.
csv_fault_2.jpg
 
Upvote 0

Forum statistics

Threads
1,214,942
Messages
6,122,367
Members
449,080
Latest member
Armadillos

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