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
Updated 14-Apr-11 23:14pm

1 solution

For VB.NET you could use the detectEncodingFromByteOrderMarks parameter of the StreamReader class to detect this.[^]

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.[^]

For reading you could use the FileSystemObject that has support for default, ASCII and unicode.[^]

Good luck!
Share this answer
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:
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.

To test if the file is unicode you can also have a look at this:
ngthtra 18-Apr-11 2:59am    
this way is applyed for unicode,I am using EUC and 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