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