In order to capture link to file using drag'n'drop I have implemented this routine:
Sub TreeView1_OLEDragDrop(Data As MSComctlLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single)
'link captured
LinkToPass = Data.Files(1)
After capturing link I am using LinkToPass variable to create hyperlink in Excel cell. Everything works fine until I drop file containing UTF-8 characters in the name (because VBA works in unicode).
After surfing the threads I got an idea to change UTF-8 to unicode while working in VBA. Using answer from this question I have build Function and test sub which works:
Dim testConversion As String
test = UTF8to16(ActiveSheet.Range("E15").Value)
ActiveSheet.Range("E16").Value = test
End Sub
In cell "E15"
of ActiveSheet I have ąčęėįšųū
written. After running this routine, in cell "E16"
I am getting same result (as intended). Just to make sure it is the Function that works - for test run I have tried removing UTFto16
Function call and just saving "E15"
value to test
variable and passing it to "E16"
resulting in mismatch (as expected).
However I have encountered problem when tried to apply same for my Drag'n'drop sub. Relevant part of my code looked like this:
'link captured
LinkToPass = UTF8to16(Data.Files(1))
Despite this method working for test sub now I was getting same incorrect (without UTF-8 characters) path to file dropped.
As I understand problem is that Data.Files(1)
passing already messed up string.
Is there a way to make Data.Files(1)
to pass string with UTF-8 characters? Or any other way to capture and change UTF-8 characters to unicode before passing them to VBA?