chinese can't load excel with VBA

SEONGMIN LIM 1 Reputation point
2021-09-14T05:16:33.703+00:00

WIN 10(Korea)
EXCEL 2016 & VBA

VBA doesn't read chinese character folder and files .
Korean & English isn't show any issue.
Doesn't VBA support chinese?

131831-p1.jpg

{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 112.8K Reputation points
    2021-09-14T09:23:35.597+00:00

    Maybe it will work if you use the Unicode version of the functions.

    I have the 64-bit Excel; the next modifications seems to help:

    Public Type BROWSEINFO
        hWndOwner As LongPtr
        pidlRoot As LongPtr
        pszDisplayName As String
        lpszTitle As String
        ulFlags As Long
        lpfnCallback As LongPtr
        lParam As LongPtr
        iImage As Long
    End Type
    
    Public Declare PtrSafe Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderW" (lpBrowseInfo As BROWSEINFO) As LongPtr
    Public Declare PtrSafe Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListW" (ByVal pidList As LongPtr, ByVal lpBuffer As String) As Boolean
    
    Public Const BIF_RETURNONLYFSDIRS = &H1
    Public Const MAX_PATH = 260 
    
    ‘ . . . .
    
    Dim bi As BROWSEINFO
    Dim pidl, Path As String
    Path = Space(MAX_PATH * 2)
    bi.lpszTitle = "Directory"
    bi.ulFlags = BIF_RETURNONLYFSDIRS
    pidl = SHBrowseForFolder(bi)
    
    Dim lResult As Long
    
    lResult = SHGetPathFromIDList(ByVal pidl, ByVal Path)
    If lResult Then
        Path = StrConv(Path, vbFromUnicode)
        TextBox1.Text = Path
    End If
    

    The checked folder name — “文件夹”— was displayed correctly in textbox. (However, the MsgBox and the Debugger are not able to display it).

    1 person found this answer helpful.