Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a application in VBA(Exel) but my application can not read CSV file that its format is EUC while format SJIS is ok.

So how to change form CSV EUC to CSV SJIS?

Could you help me?
thanks
Posted

1 solution

Try this:
Option Explicit

Sub SaveAsSJIS(sFullName As String)
Dim oWbk As Workbook

On Error GoTo Err_SaveAsSJIS

Set oWbk = Workbooks.Add
oWbk.WebOptions.Encoding = msoEncodingJapaneseShiftJIS
oWbk.SaveAs Filename:=sFullName, FileFormat:=xlCSV, TextCodepage:=msoEncodingJapaneseShiftJIS
oWbk.Close SaveChanges:=True

Exit_SaveAsSJIS:
    On Error Resume Next
    Set oWbk = Nothing
    Exit Sub

Err_SaveAsSJIS:
    MsgBox Err.Description, vbExclamation, Err.Number
    Resume Exit_SaveAsSJIS

End Sub

Usage:
Sub TestTextCodePage()
    SaveAsSJIS "C:\testCP.csv"
End Sub


I think, the TextCodepage variable is equal to MsoEncodingEnumeration. See it on: http://office.microsoft.com/en-ca/excel-help/HV080559483.aspx[^]
 
Share this answer
 
Comments
ngthtra 17-Apr-11 22:36pm    
thanks losmac, but your code has problem which files will be lost their data after this code run.
I want to my application can read both csv file with EUC format and Shift-JIS.If csv file is Shift-JIS, read normally. else if csv file is EUC, convert from EUC to Shift-JIS and then read it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900