Is it possible to force Excel recognize UTF-8 CSV files automatically?

后端 未结 27 1659
醉梦人生
醉梦人生 2020-11-21 22:27

I\'m developing a part of an application that\'s responsible for exporting some data into CSV files. The application always uses UTF-8 because of its multilingual nature at

27条回答
  •  说谎
    说谎 (楼主)
    2020-11-21 22:51

    Simple vba macro for opening utf-8 text and csv files

    Sub OpenTextFile()
    
       filetoopen = Application.GetOpenFilename("Text Files (*.txt;*.csv), *.txt;*.csv")
       If filetoopen = Null Or filetoopen = Empty Then Exit Sub
    
       Workbooks.OpenText Filename:=filetoopen, _
       Origin:=65001, DataType:=xlDelimited, Comma:=True
    
    End Sub
    

    Origin:=65001 is UTF-8. Comma:True for .csv files distributed in colums

    Save it in Personal.xlsb to have it always available. Personalise excel toolbar adding a macro call button and open files from there. You can add more formating to the macro, like column autofit , alignment,etc.

提交回复
热议问题