4

我正在尝试使用以下行打开一个文件以在 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

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

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

4

1 回答 1

6

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. 
于 2012-06-12T13:34:23.707 回答