我创建了一个简单的Excel工作表。
这是我的宏代码:
Sub MyMacro()
Sheets("Sheet1").Select
A$ = Cells(1, 1)
MsgBox (A$)
End Sub
如果Cell 1,1包含英文单词或数字,则它的工作正确。
但是当我将一些波斯语/阿拉伯语文本放入Cell 1,1(例如:سلام
)并运行宏时,宏显示????
。 (它显示?
而不是每个波斯字符
如何解决这个问题?
答案 0 :(得分:4)
您可以使用Windows API消息框,它应显示大多数编码类型
例如,这会进入MODULE
Option Explicit
#If Win64 Then
Private Declare PtrSafe Function User32MsgBox Lib "user32" Alias "MessageBoxW" _
(Optional ByVal hWnd As Long, Optional ByVal Prompt As Long, _
Optional ByVal Title As Long, Optional ByVal Buttons As Long) As Long
#Else
Private Declare Function User32MsgBox Lib "user32" Alias "MessageBoxW" _
(Optional ByVal hWnd As Long, Optional ByVal Prompt As Long, _
Optional ByVal Title As Long, Optional ByVal Buttons As Long) As Long
#End If
Public Function MessageBoxW(cPrompt As String, _
Optional cButtons As VbMsgBoxStyle = vbOKOnly, _
Optional cTitle As String) As Long
MessageBoxW = User32MsgBox(0, StrPtr(cPrompt), StrPtr(cTitle), cButtons)
'*****Probably need to convert StrPtr to 32bit long on 64bit - see next line
'MessageBoxW = User32MsgBox(0, cLng(StrPtr(cPrompt)), CLng(StrPtr(cTitle)), cButtons)
End Function
Sub MyMacro()
Dim txt As String
txt = Sheets("Sheet1").Cells(1, 1).Value
MessageBoxW (txt)
End Sub
我目前没有配备64位机器,因此您可能需要在64位机器上将StrPtr转换为32位长