I've been working on SeleniumVBA functionality for proper handling of Unicode directory and file paths. In the process, I came across the following surprise (to me).
Apparently on my system, native VBA7 functionality (Excel 365) blows up when trying to access/manipulate file names and paths that contain non-ANSI characters. In VBA, the following code never makes it past the MKDir command at runtime, and will also fail on Open, Kill, Dir, and RmDir commands.
I naively thought that VBA strings, represented as Unicode, would work with native file commands, but apparently not.
Can anyone else confirm that the following code fails in VBA? Thx!
PS: FileSystemObject and ADODB stream properly handle Unicode directory and file paths - so it is not too high an expectation for native VBA functionality to do the same, I think. But wanted to make sure that it is not something unique to my setup.
Sub test_unicode()
Dim folderPath As String
Dim filePath As String
Dim fileNum As Long
'create a folder with non-Ansi (unicode) characters
folderPath = Environ("USERPROFILE") & "\Documents\" _
& ChrW(&H259) & ChrW(&H259) & ChrW(&H259)
MkDir folderPath
'create a file with non-Ansi (unicode) characters
'in the file name
filePath = folderPath & "\" & "test" _
& ChrW(&H278) & ".txt"
fileNum = FreeFile
Open filePath For Output As #fileNum
Print #fileNum, "test line"
Close #fileNum
'check if success
Debug.Print Dir(filePath) <> vbNullString
'now clean up
Kill filePath
RmDir folderPath
End Sub
I've been working on SeleniumVBA functionality for proper handling of Unicode directory and file paths. In the process, I came across the following surprise (to me).
Apparently on my system, native VBA7 functionality (Excel 365) blows up when trying to access/manipulate file names and paths that contain non-ANSI characters. In VBA, the following code never makes it past the MKDir command at runtime, and will also fail on Open, Kill, Dir, and RmDir commands.
I naively thought that VBA strings, represented as Unicode, would work with native file commands, but apparently not.
Can anyone else confirm that the following code fails in VBA? Thx!
PS: FileSystemObject and ADODB stream properly handle Unicode directory and file paths - so it is not too high an expectation for native VBA functionality to do the same, I think. But wanted to make sure that it is not something unique to my setup.