Starting off in VBA and trying to set up a bilingual worksheet. One part is to include both Arabic and English text in MsgBoxes. I have tried changing my regional settings and can now paste Arabic chars in the VBA Editor however they are displayed as different chars in the message text. (see image)
My current approach is to convert the text to Unicode and join first the letters, then the English text in a separate function (apologies in advance for the poor code):
Sub exampleMsg()
Dim Atxt As String
Dim Etxt As String
Atxt = "\u0627\u062e\u062a\u0628\u0627\u0631\u0627\u062a"
Etxt = "testing"
MsgBox (AddArabic(Atxt, Etxt))
End Sub
with the AddArabic() function:
Function AddArabic(ARtxt As String, ENtxt As String)
arr = Split(ARtxt, "\u")
Dim uStr, s As String
Dim uNum As Integer
For Each uStr In arr
uNum = CInt(uStr)
s = s & ChrW(uNum)
Next uStr
s = s & vbNewLine & vbNewLine & ENtxt
AddArabic = s
End Function
This seems to work for most chars however as a non-Arabic speaker bound to Google translate I keep running into issues with letters that seem to have a non-numeric UTF index (e.g. u062a
for ta'a). Understandably these can't be converted to Int
.
I've scoured the web for a similar problem but can't seem to find any cases, leading to the assumption that I've misunderstood the ChrW
fuction or my options in general. Any help would be much appreciated!
Tried:
- Change the devices regional setting and insert Arabic text directly
- Create array of Unicode references and assemble string manually
- Pass Unicode references as String instead of Int (was worth a try)
- Read string from a cell and use .Value as MsgBox String
Expected: Message Box to handle foreign chars or Unicode reference to be numeric only