如何使用Excel VBA获取阿拉伯语月份名称

在Excel VBA中,我试图把“一个月的阿拉伯名字”放在一个variables中,我find了一个方法。 但我的方式需要一个缓冲单元来放置值,更改单元格格式,检索单元格的文本值,然后将该值放入一个variables。

这是我的VBA代码:

Sub GetArabicName() Sheets("Sheet1").Cells(1, 1).Value = date() Sheets("Sheet1").Cells(1, 1).NumberFormat = "[$-10A0000]mmmm;@" ArabicMonth = Sheets("Sheet1").Cells(1, 1).Text MsgBox ArabicMonth & " The Arabic Name of the Month" End Sub 

有没有更简单的方法来使用VBA,而不使用缓冲区单元? 另外,如何使MsgBox显示阿拉伯数值不是“?????”

先谢谢你。

我不能删除帮助单元的需要,但是这会得到一个消息types的框来显示文本:

 Public Declare Function MessageBoxU Lib "user32" Alias "MessageBoxW" _ (ByVal hwnd As Long, _ ByVal lpText As Long, _ ByVal lpCaption As Long, _ ByVal wType As Long) As Long Sub GetArabicName() Dim ArabicMonth As String With Sheets("Sheet1").Cells(1, 1) .Value = Date .NumberFormat = "[$-10A0000]mmmm;@" .Font.Name = "Arial Unicode MS" ArabicMonth = .Text End With MessageBoxU 0, StrPtr(ArabicMonth), StrPtr("MsgBox Substitute"), 0 MsgBox ArabicMonth & " The Arabic Name of the Month" End Sub 

在这里输入图像说明

改编自:

Renaud Bompuis

编辑#1:

基于Axel Richter的出色build议,这样就不需要辅助单元了:

 Sub GetArabicNames_II() Dim ArabicMonth As String ArabicMonth = Application.WorksheetFunction.Text(Date, "[$-10A0000]mmmm;@") MessageBoxU 0, StrPtr(ArabicMonth), StrPtr("MsgBox Substitute"), 0 End Sub