尝试使用Unicode文件名或路径名设置变量
当前工作簿路径仅包含ĄČĘĖĮŠŲŪŽ
正确显示的立陶宛字符ŠŽ
Private Declare PtrSafe Function GetFileAttributesW Lib "kernel32.dll" (ByVal lpFileName As LongPtr) As Long
Private Declare PtrSafe Function GetCurrentDirectory Lib "kernel32" _
Alias "GetCurrentDirectoryW" _
(ByVal nBufferLength As LongPtr, ByVal lpBuffer As String) As Long
Sub test()
Dim buff As String * 420
Dim Shell32 As New Shell32.Shell, Item As Shell32.ShellFolderItem
strFile = ThisWorkbook.path & "\test.txt"
len_dir = GetCurrentDirectory(200, buff)
test1 = CreateObject("WScript.Shell").CurrentDirectory & "\test.txt": result1 = GetCsvData(test1) ' Error Path not found
test2 = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".") & "\test.txt": result2 = GetCsvData(test2) ' Error Path not found
test3 = Dir(ThisWorkbook.path & "\test.txt"): result3 = GetCsvData(test3) ' Error Path not found
test4 = strFile: result4 = GetCsvData(test4) ' Error Path not found
test5 = Left(buff, len_dir + len_dir) & "\test.txt": result5 = GetCsvData(test5) ' Bad filename or number, GetFileAttributesW error, TextOutW error, GetShortPathNameW error
test6 = Shell32.Namespace(ThisWorkbook.path).Items.Item(0).path & "\test.txt": result6 = GetCsvData(test6) ' Error Path not found
test7 = CurDir & "\test.txt": result7 = GetCsvData(test7) ' Error Path not found
Stop
End Sub
Function GetCsvData(backUpName) As Variant
Dim MyData As String, strData() As String
Open backUpName For Binary As #1
MyData = Space$(LOF(1))
Get #1, , MyData
Close #1
GetCsvData = MyData
End Function
也不了解testį的含义是文件名中的方格,就像将其写入已消失的文件方格中一样,但是从此文件中读回时,方格卷土重来。
那么如何在路径和文件名中使用Unicode字符?