将 Unicode 字符串转换为 ChrW() 格式

问题描述 投票:0回答:1

回复如下: 文字 我想要一个 VBA 代码来将以希伯来字符编写的短字符串转换为 ChrW() 格式。

整个希伯来字母表的字符串,末尾有一个空格:

אבגדהוזחטיךכלםמןנסעףפצקרשת 

应该看起来像这样:

ChrW(1488) & ChrW(1489) & ChrW(1490) & ChrW(1491) & ChrW(1492) & ChrW(1493) & ChrW(1494) & ChrW(1495) & ChrW(1496) & ChrW(1497) & ChrW(1498) & ChrW(1499) & ChrW(1500) & ChrW(1501) & ChrW(1502) & ChrW(1503) & ChrW(1504) & ChrW(1505) & ChrW(1506) & ChrW(1507) & ChrW(1508) & ChrW(1510) & ChrW(1511) & ChrW(1512) & ChrW(1513) & ChrW(1514) & ChrW(32)
excel vba unicode
1个回答
0
投票

这是一种方法。为此,请将 unicode 字符串放入

A1
的单元格
Sheet1
中。您无法将字符串存储在 VBA 变量中,因为不支持 unicode。

假设有一个文件夹

C:\שם_התיקייה_שלי

在 VBE 的模块中,粘贴以下代码。

Option Explicit

Sub Sample()
    Dim ws As Worksheet
    Dim ConvertedUniString As String
    Dim UniCodeCellAddress As String
    Dim i As Long
    
    '~~> Change this to the relevant sheet
    Set ws = Sheet1
    
    '~~> This is the cell address where the unicode string is
    UniCodeCellAddress = "A1"
    
    With ws
        '~~> Loop through the unicode characters to
        '~~> get the ChrW value and join them
        For i = 1 To Len(.Range(UniCodeCellAddress))
            ConvertedUniString = ConvertedUniString & _
            ChrW(.Evaluate("UNICODE(MID(" & UniCodeCellAddress & "," & i & ",1))"))
        Next i
        
        '~~> Discard the initial empty space
        ConvertedUniString = Mid(ConvertedUniString, 1)
        
        '~~> Uncomment the below to see the converted string
        '~~> in a cell. You can't use MSGBOX as Unicode is not
        '~~> Supported in VBA.
        '.Range("A10").Value = "c:\" & ConvertedUniString
        
        '~~> Launch the Folder
        Shell "Explorer.exe c:\" & ConvertedUniString, vbNormalFocus
    End With
End Sub

当您运行上述代码时,shell 将启动该文件夹。

© www.soinside.com 2019 - 2024. All rights reserved.