Search code examples
excelvbaunicode

Open Shell command from Excel-VBA with variant Unicode-folder


I would like to open the Explorer from Excel-VBA, in a folder that the user chooses and the folder is not in English. I saved the folder name in the ChrW code.

When I use the following code the Explorer opens in the correct folder:

Sub Show_Folder()
    Shell "Explorer.exe c:\" & ChrW(1488) & ChrW(1502) & ChrW(1488), vbNormalFocus
End Sub

but when I use a variant, the Explorer opens in its default position:

Sub Show_Folder()
    Dim FolderCode As String
    FolderCode = "ChrW(1488) & ChrW(1502) & ChrW(1488)"
    Shell "Explorer.exe c:\" & FolderCode, vbNormalFocus
End Sub

I tried to play with FolderCode adding "&" and " & " to its start with no luck... What am I missing?


Solution

  • Sub ShowFolder2()
      Dim FolderCode  As String
    FolderCode = ChrW(1488) & ChrW(1502) & ChrW(1488)
    Shell "Explorer.exe C:\" & FolderCode & ", vbNormalFocus"
    
    End Sub
    

    Edit
    Although inefficient, if, for the reasons you stated in your comment, FolderCode contains the actual string "ChrW(1488) & ChrW(1502) & ChrW(1488)", you could replace ChrW with Unichar to create an Excel formula, and then apply the Evaluate function.

    It would seem more efficient for your drop-down to contain the actual letters or even the corresponding Excel function UNICHAR.

    Option Explicit
    
    Sub ShowFolder2()
      Dim FolderCode  As String
    
    FolderCode = "ChrW(1488) & ChrW(1502) & ChrW(1488)"
    FolderCode = Evaluate(Replace(FolderCode, "ChrW", "UNICHAR"))
    
    Shell "Explorer.exe C:\" & FolderCode & ", vbNormalFocus"
    
    End Sub