我编写了一个快速操作来生成一个表,以便在使用 ALT 代码时用作参考。我得到的输出与在单元格中键入时实际显示的输出不匹配。例如,输出显示 ALT + 3 应为此┘
,但如果我实际输入 ALT + 3 ,显示此♦
。
我知道我可以使用CHRw()
来实现任何角色,但我想我在这里寻找的是,如果有一个直接代码相当于持有 ALT 并按数字组合。
以下是我用来生成表格的代码:
Sub CHARACTER_TABLE()
'DEFINE VARIABLES
Dim CROW As Integer
Dim CCOL As Integer
Dim A As Integer
CROW = 2
CCOL = 1
A = 1
Do
Cells(CROW, CCOL) = A
Cells(CROW, (CCOL + 1)) = Chr(A)
CROW = CROW + 1
A = A + 1
If CROW = 42 Then
CROW = 2
CCOL = CCOL + 3
End If
If A = 256 Then
Exit Do
End If
Loop
End Sub
答案 0 :(得分:0)
对于没有前导零的代码,该字符将从系统OEM代码页转换:
ALT + 128 gives "Ç" with the code page 487 (https://en.wikipedia.org/wiki/Code_page_437)
对于前导零的代码,该字符将从系统ANSI代码页转换:
ALT + 0128 gives "€" with the code page 1251 (https://en.wikipedia.org/wiki/Windows-1251)
列出工作表中的默认OEM和ANSI字符:
Private Declare Function MultiByteToWideChar Lib "kernel32" ( _
ByVal codepage As Long, ByVal dwFlags As Long, _
ByRef lpMultiByteStr As Any, ByVal cchMultiByte As Long, _
ByRef lpWideCharStr As Any, ByVal cchWideChar As Long) As Long
Function ChrEx(ByVal code As Integer, ByVal codepage As Long) As String
Dim tgt(0 To 1) As Byte
MultiByteToWideChar codepage, 4, code, 2, tgt(0), 2
ChrEx = tgt
End Function
Sub DisplayCharSets()
Dim r&, chars(1 To 255, 1 To 1) As String
'List the system OEM code page in range A1
chars(1, 1) = "OEM"
For r = 2 To 255
chars(r, 1) = ChrEx(r, 1) ' Default OEM code page = 1
Next
[A1:A255] = chars
'List the system ANSI code page in range B1
chars(1, 1) = "ANSI"
For r = 2 To 255
chars(r, 1) = ChrEx(r, 0) ' Default ANSI code page = 0
Next
[B1:B255] = chars
End Sub