question

SEONGMINLIM-8904 avatar image
0 Votes"
SEONGMINLIM-8904 asked SEONGMINLIM-8904 edited

chinese can't load excel with VBA

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



office-vba-dev
p1.jpg (22.5 KiB)
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


How to reproduce the problem using a simple VBA code?


0 Votes 0 ·

131690-%E1%84%8C%E1%85%A6%E1%84%86%E1%85%A9%E1%86%A8-%E1%84%8B%E1%85%A5%E1%86%B9%E1%84%8B%E1%85%B3%E1%86%B7.png





 Dim bi As BROWSEINFO
 Dim pidl, Path As String * 512
 bi.lpszTitle = "Directory"
 bi.ulFlags = BIF_RETURNONLYFSDIRS
 pidl = SHBrowseForFolder(bi)
  
 lResult = SHGetPathFromIDList(ByVal pidl, ByVal Path)
 If lResult Then
     TextBox1.Value = Path
     WriteFiles
 End If
 Exit Sub

Path and file in the picture. VB read EN and KR but chinese are show "?"

In my think that language problem.

0 Votes 0 ·
Viorel-1 avatar image Viorel-1 SEONGMINLIM-8904 ·

If you mean that “?” are shown in Watch window of Debugger, I think that you can ignore this issue. Check if the value is correct in TextBox1.

It seems that you are using external functions. Show the definitions of SHBrowseForFolder, SHGetPathFromIDList, BROWSEINFO.

By the way, you shown a picture that reflects a run-time error. Which line generates the error?


0 Votes 0 ·
Show more comments

1 Answer

Viorel-1 avatar image
1 Vote"
Viorel-1 answered SEONGMINLIM-8904 edited

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Really Thanks for your help.

Unfortunately, I can't modified your codes. The path of the folder is mixed of Unicode(Chinese) and ASCII code.

ex) G:\2021\2_VBA\한글\中文\圆圆圆.txt

Last VBA shows : G:\2021\2_VBA\한글\??\???.txt


All value is broken after convert Unicode.

Current VBA shows : G:\2021\2_VBA\???\???\???.txt

I can't change my development conditions and usually used ASCII condition.

0 Votes 0 ·