Click here to Skip to main content
15,937,779 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have some file CSV and I want to get their encoding type using VBA in Exel.

but I can not do this.

Could you help me resolve this problem?

thanks for advance
Posted
Updated 14-Apr-11 23:14pm
v2

1 solution

For VB.NET you could use the detectEncodingFromByteOrderMarks parameter of the StreamReader class to detect this.
http://msdn.microsoft.com/en-US/library/akzyzwh9%28v=VS.80%29.aspx[^]

Unfortunately this isn't available for VBA/VB6. Possibly you could detect it yourself by reading the first bytes from it and use that to determine the encoding.
http://codesnipers.com/?q=node/68[^]


For reading you could use the FileSystemObject that has support for default, ASCII and unicode.
http://msdn.microsoft.com/en-us/library/314cz14s%28v=VS.85%29.aspx[^]

Good luck!
 
Share this answer
 
Comments
ngthtra 15-Apr-11 3:22am    
Thanks your link. But I can not find way that help me resolve my problem.
can you tell me how to use streamReader on VBA(code in Exel)?
because If use streamReader in VB.NET I can get encoding type of CSV file.
E.F. Nijboer 15-Apr-11 4:31am    
You use the FileSystemObject for that. This returns a TextStream that you can then use. I actually don't know if VBA has any support for other encodings. However, I have two other links that might interest you:
http://www.nonhostile.com/howto-convert-byte-array-utf8-string-vb6.asp
http://www.tek-tips.com/viewthread.cfm?qid=1392917
ngthtra 15-Apr-11 5:31am    
they don't resolve this problem, I need get encoding while they convert.and now I try to filesystemobject, I not sure that it is good
E.F. Nijboer 15-Apr-11 7:41am    
I think the second link (codesnipers) can help you with this. You simply read the text file into a byte array (although I think you don't need the complete file for this) and check for a signature. If no signature is found then assume ansi.
http://www.nonhostile.com/howto-read-write-byte-arrays-files-vb6.asp

To test if the file is unicode you can also have a look at this:
http://www.apihosting.com.ar/manuales/es/online/vbapi/apidetail.asp?api_id=471
ngthtra 18-Apr-11 2:59am    
this way is applyed for unicode,I am using EUC and Shift_JIS.how to determine what file is EUC and What file is Shift_JIS?

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