【发布时间】:2018-06-01 01:49:19
【问题描述】:
我正在尝试打开一个具有 Unicode 文件名的文件以进行二进制访问以计算 MD5 校验和。我将文件名和路径正确存储在 Excel 表中。
然后代码在Open sPath For Binary Access Read As lngFileNumber 失败,'Run-Time error'52': Bad file name or number
Function GetFileBytes(ByVal sPath As String) As Byte()
' makes byte array from file
Dim lngFileNum As Long, bytRtnVal() As Byte, bTest
lngFileNum = FreeFile
If LenB(Dir(sPath)) Then ''// Does file exist?
Open sPath For Binary Access Read As lngFileNum
'a zero length file content will give error 9 here
ReDim bytRtnVal(0 To LOF(lngFileNum) - 1&) As Byte
Get lngFileNum, , bytRtnVal
Close lngFileNum
Else
Err.Raise 53 'File not found
End If
GetFileBytes = bytRtnVal
Erase bytRtnVal
End Function
有什么建议吗?
【问题讨论】:
标签: excel unicode-string vba