file - 打开输入 VB 时指定编码

标签 file vba encoding

我正在尝试使用以下行打开一个文件以在 Excel 中输入:

Open tmpNmFichier For Input Shared As #iFnum

问题是我的文件有一些字符,如:“é”、“à”……当我用以下内容解析文件时:
Dim s As String

Line Input #iFnum, s
If Len(s) > 0 Then
     v = Split(s, tmpSeparateur)
Else
    ReDim v(-1 To -1)
End If

我的字符“é”...被转换为:“è”或“Ã...”

你知道我如何明确我的文件的编码或类似的东西吗?

最佳答案

使用 FileSystemObject相反

Public Function GetContent(fpath$) As String
    'REFERENCES:
    'Microsoft Scripting Runtime // Scripting.FileSystemObject
    Dim fso As New Scripting.FileSystemObject, content$
    If fso.FileExists(fpath) Then
        content = fso.OpenTextFile(fpath, ForReading, False, TristateTrue).ReadAll()
        GetContent = content
    Else
        MsgBox "Invalid file path."
        GetContent = vbNullChar
    End If
End Function


TristateUseDefault -2 Opens the file using the system default. 
TristateTrue -1 Opens the file as Unicode. 
TristateFalse  0 Opens the file as ASCII. 

关于file - 打开输入 VB 时指定编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10996922/

相关文章:

java - Mule 3.7.3 - Dataveawe 消息转换器编码错误

bash:对于文件是否存在?

c++ - fopen 或 fstream 等是否会意外破坏文件 C/C++

excel - 使用excel从特定字符中删除序列

sql - 将数据从一个临时表复制到主表

ms-access - 如何增加 Access 中的日历大小?

php - mb_strlen() 和 strlen() 不会从对 PHP 的 Ajax 调用返回正确的值

python - 我的 Python 应用程序需要包含哪些文件?

python - 将二维列表写入文件、读出并重新使用保存的列表

mysql - LuaLaTeX - 字符串包含无效的 utf-8 序列